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

HTML DOM Audio loop attribute

Audio loop attribute

Audio Object Reference Audio object

Example

Set the audio to loop playback:

document.getElementById("myAudio").loop = true;

Try it »


Definition and Usage

The loop attribute sets or returns whether the audio should play again when it ends.

This property reflects

When this attribute is used, the audio continues playing after it ends.

Note:


Browser support

Internet ExplorerFirefoxOperaGoogle ChromeSafari

All major browsers support the loop attribute.

Note: Internet Explorer 8 and earlier IE versions do not support this attribute.


Syntax

Return the loop attribute:

audioObject

.loop

Set the loop attribute:

audioObject

.loop=true|false

Attribute values

Value Description
true|false Indicates whether the audio plays again when it ends.
  • true - indicates that the audio plays again when it ends.
  • false - default. Indicates that the audio does not play again when it ends.
  • |

    Technical Details

    Return Value: Boolean. Returns true if the audio loops, otherwise false.
    Default value: false

    More examples

    Example

    Check whether the audio plays again after finishing:

    var x = document.getElementById("myAudio").loop;

    x

    The output is:

    true

    Try it »


    Related pages

    HTML Reference Manual: HTML


    Audio Object Reference Audio object