W3Schools.com
THE WORLD'S LARGEST WEB DEVELOPER SITE
HTMLCSSJAVASCRIPTSQLPHPJQUERYBOOTSTRAPANGULARXML
 

Audio autoplay Property

Audio Object Reference Audio Object

Example

Find out if the audio started to play as soon as it was ready:

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

The result of x will be:

true

Try it yourself »

Definition and Usage

The autoplay property sets or returns whether the audio should start playing as soon as it is loaded.

This property reflects the <audio> autoplay attribute.

When present, it specifies that the audio should automatically start playing as soon as it is loaded.

Note: The <audio> element is new in HTML5.


Browser Support

Internet Explorer Firefox Opera Google Chrome Safari

The autoplay property is supported in all major browsers.

Note: Internet Explorer 8 and earlier versions, do not support the <video> element.


Syntax

Return the autoplay property:

audioObject.autoplay

Set the autoplay property:

audioObject.autoplay=true|false

Property Values

Value Description
true|false Specifies whether an audio should automatically start playing as soon as it is loaded
  • true - Indicates that the audio should start playing as soon as it is loaded loaded
  • false - Default. Indicates that the audio should NOT start playing as soon as it is loaded

Technical Details

Return Value: A Boolean, returns true if the audio automatically starts playing, otherwise it returns false
Default Value: false 

More Examples

Example

Enable autoplay, and reload the video:

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

Try it yourself »

Example

A demonstration of how to create a <video> element and setting the autoplay property:

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

Try it yourself »

Related Pages

HTML reference: HTML <audio> autoplay attribute


Audio Object Reference Audio Object