Private archive copy · Unofficial site · Content copyright belongs to Runoob Tutorial and the original authors · View Original

HTML DOM Audio autoplay Property

Audio autoplay Property

Audio Object Reference Audio object

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

Internet ExplorerFirefoxOperaGoogle ChromeSafari

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.
  • true - automatically starts playing after the audio has finished loading.
  • false - default. Does not auto-play after the audio has finished 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 Reference Audio object