The autoplay Attribute
Example
Check if the audio is set to play immediately after loading:
Definition and Usage
The autoplay attribute sets or returns whether the audio or video should start playing as soon as it is loaded.
This attribute reflects the <audio> autoplay attribute.
If the autoplay attribute is set, it specifies that the audio will start playing immediately after it is loaded.
Note: The <audio> element is a new element in HTML5.
Browser Support
The autoplay property is supported by all major browsers.
Note: The <video> element is not supported in Internet Explorer 8 and earlier versions.
Syntax
Return the autoplay attribute:
Set the autoplay attribute:
Attribute Values
| Value | Description | |
|---|---|---|
| true | false | Sets whether the audio or video should start playing immediately after loading. true - Starts playing the audio automatically after it is loaded.<br> false - Default. Does not start playing the audio automatically after it is loaded. |
Technical Details
| Return Value: | Boolean, returns true if the audio is set to autoplay, otherwise returns false. |
|---|---|
| Default Value: | false |
| --- | --- |
More Examples
Example
Enable autoplay and reload the video:
var x = document.getElementById("myAudio");
x.autoplay = true;
x.load();
Example
The following example demonstrates how to create a <video> element and set the autoplay attribute:
Related Pages
HTML Reference: HTML <audio> autoplay Attribute