Audio autoplay Property
Example
Check whether the audio is set to play immediately after loading:
var x = document.getElementById("myAudio").autoplay;
x
The output is:
true
Try it »
Definition and Usage
The autoplay property sets or returns whether the audio/video starts playing immediately after loading.
This property reflects
If the autoplay attribute is set, it specifies that the audio plays immediately after loading.
Note:
Browser support





All major browsers support the autoplay property.
Note: Internet Explorer 8 and earlier IE versions are not supported.
Syntax
Returns the autoplay attribute:
audioObject
.autoplay
Set the autoplay attribute:
audioObject
.autoplay=true|false
Attribute values
| Value | Description |
|---|---|
| true|false | Sets whether the audio/video starts playing immediately after loading.
|
Technical Details
| Return Value: | A boolean that returns true if the audio autoplay is set, otherwise 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 »
Example
The following example demonstrates how to create
var x = document.createElement("AUDIO");
Try it »
Related pages
HTML Reference Manual: HTML
Audio object