Audio autoplay attribute
Definition and usage
autoplay
attribute settings or returns whether the audio should start playing immediately after loading.
This attribute reflects <audio> autoplay attribute.
If it exists, it specifies that the audio should start playing automatically immediately after loading.
Example
Example 1
Check if the audio starts playing immediately after being ready:
var x = document.getElementById("myAudio").autoplay;
Example 2
Enable autoplay and reload the video:
var x = document.getElementById("myAudio"); x.autoplay = true; x.load();
Example 3
Demonstrate how to create a <video> element and set the autoplay attribute:
var x = document.createElement("AUDIO");
Syntax
Return the autoplay attribute:
audioObject.autoplay
Set the autoplay attribute:
audioObject.autoplay = true|false
Attribute value
Value | Description |
---|---|
true|false |
Specifies whether the audio should start playing immediately after loading.
|
Technical Details
Return Value: | Boolean value, returns true if the audio starts playing automatically, otherwise returns false. |
---|---|
Default Value: | false |
Browser Support
Chrome | Edge | Firefox | Safari | Opera |
---|---|---|---|---|
Chrome | Edge | Firefox | Safari | Opera |
Support | Support | Support | Support | Support |
Related Pages
HTML Reference Manual:HTML <audio> autoplay Attribute