Video autoplay Property - Javascript DOM HTML Element

Javascript examples for DOM HTML Element:Video


The autoplay property sets or gets whether a video should start playing as soon as it is loaded.

This property reflects the <video> autoplay attribute.

Set the autoplay property with the following Values

Value Description
true|false Sets whether a video should automatically start playing as soon as it is loaded

Return Value

A Boolean, returns true if the video automatically starts playing, otherwise it returns false

Default Value is false

The following code shows how to check if the video started to play as soon as it was ready:

Demo Code

ResultView the demo in separate window

<!DOCTYPE html>

<video id="myVideo" width="320" height="240" controls>
  <source src="your.mp4" type="video/mp4">
  <source src="your.ogg" type="video/ogg">
  Your browser does not support the video tag.

<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>

var x = document.getElementById("myVideo");

function enableAutoplay() {/* w w  w  .jav a2  s  .c om*/
    x.autoplay = true;

function disableAutoplay() {
    x.autoplay = false;

function checkAutoplay() {


Related Tutorials