HTML Audio & Video

HTML DOM Audio autoplay Property

The autoplay property sets or returns whether a media element should start playing as soon as it has loaded enough data. It reflects the autoplay HTML attribute and is a boolean.


Definition and Usage

When autoplay is true, the browser attempts to begin playback automatically without waiting for the user to press play. The property directly reflects the presence of the autoplay attribute on the element.

Syntax

// Get the value
let auto = mediaElement.autoplay;

// Set the value
mediaElement.autoplay = true;

The property returns true if autoplay is enabled and false otherwise. Assigning a boolean adds or removes the underlying attribute.

Example

Enabling autoplay on a muted video
<video id="myVideo" width="320" muted controls>
  <source src="movie.mp4" type="video/mp4">
</video>

<script>
const video = document.getElementById("myVideo");
video.autoplay = true;   // enable autoplay via JavaScript
console.log(video.autoplay); // true
</script>

Note the muted attribute in the example. Modern browsers block autoplay with sound, but they generally allow muted autoplay, so combining the two is the reliable pattern for background or hero videos.

⚠️

Setting autoplay = true is not a guarantee. If the browser's autoplay policy blocks playback (for example, unmuted media without user interaction), it silently ignores the request and the media stays paused.

Ready to use your HTML skills?

Find web development internships and fresher jobs across India.

Browse Web Dev Internships