Video autoplay attribute

Definition and usage

autoplay It sets or returns whether the video should start playing automatically immediately after loading.

This attribute indicates <video> autoplay attribute.

If it exists, it specifies that the video should start playing automatically immediately after loading.

Example

Example 1

Check if the video starts playing immediately after it is ready:

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

Try it yourself

Example 2

Enable autoplay and reload the video:

var x = document.getElementById("myVideo");
x.autoplay = true;
x.load();

Try it yourself

Example 3

Demonstrate how to create a <video> element and set the autoplay attribute:

var x = document.createElement("VIDEO");

Try it yourself

Syntax

Return the autoplay attribute:

videoObject.autoplay

Set the autoplay attribute:

videoObject.autoplay = true|false

Attribute value

Value Description
true|false

Specify whether the video should start playing automatically immediately after loading.

  • true - Indicates that the video should start playing immediately after loading
  • false - Default. Indicates that the video should not start playing immediately after loading

Technical Details

Return Value: Boolean value, returns true if the video starts playing automatically; otherwise returns false.
Default Value: false

Browser Support

Chrome Edge Firefox Safari Opera
Chrome Edge Firefox Safari Opera
Support 9.0 Support Support Support

Related Pages

HTML Reference Manual:HTML <video> autoplay Attribute