English | 简体中文 | 繁體中文 | Русский язык | Français | Español | Português | Deutsch | 日本語 | 한국어 | Italiano | بالعربية

HTML Reference Manual

HTML Tag Directory

HTML Audio/Video DOM autoplay attribute

The autoplay property of HTMLMediaElement is equivalent to the autoplay attribute in HTML, indicating whether the video should play automatically when the player has downloaded enough media files to play. Note: Some versions of Chrome only support autostart, not autoplay

 HTML Audio/Video DOM Reference Manual

Online Example

Enable autoplay and reload the video:

<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>HTML Audio/Using the video audioTracks property-Basic Tutorial(oldtoolbag.com)</title>/<title>
</<head>
<body>
<button onclick="enableAutoplay()" type="button">Enable autoplay</button>
<button onclick="disableAutoplay()" type="button">Disable autoplay</button>
<button onclick="checkAutoplay()" type="button">Check autoplay status</button>
<br> 
<video id="video1" controls="controls">
  <source src="movie.mp4" type="video/mp4">
  <source src="movie.ogg" type="video/ogg">
  Your browser does not support HTML5 video tag.
</video>
<script>
myVid=document.getElementById("video1);
function enableAutoplay()
{ 
  myVid.autoplay=true;
  myVid.load();
} 
function disableAutoplay()
{ 
  myVid.autoplay=false;
  myVid.load();
} 
function checkAutoplay()}
{ 
  alert(myVid.autoplay);
} 
</script> 
</body>
</html>
Test and see ‹/›

Definition and Usage

autoplay attribute sets or returns whether the audio is loaded/Start playing the video immediately after the video.

Browser Compatibility

IEFirefoxOperaChromeSafari

All major browsers support the autoplay attribute.

Note:Internet Explorer 8 And earlier versions do not support this attribute.

Syntax

Set autoplay attribute:

audio|video.autoplay=true|false

Return autoplay attribute:

audio|video.autoplay

Attribute value

ValueDescription
trueIndicates the audio/The video should start playing immediately after loading.
falseDefault. Indicates the audio/The video should not start playing immediately after loading.

Technical Details

Return value:Boolean value, true|false
Default value:false
 HTML Audio/Video DOM Reference Manual