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;

Try it yourself

Example 2

Enable autoplay and reload the video:

var x = document.getElementById("myAudio");
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("AUDIO");

Try it yourself

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.

  • true - Indicates that the audio should start playing immediately after loading
  • false - Default. Indicates that the audio should not 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