Audio loop attribute

Definition and Usage

loop Whether the audio should restart playing after it ends, as set by the attribute.

This attribute reflects <audio> loop attribute.

When this attribute is set, it specifies that the audio should restart playing after it finishes.

Example

Example 1

Set the audio to loop play:

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

Try It Yourself

Example 2

Determine whether the audio should restart playing after each completion:

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

Try It Yourself

Syntax

Return the loop attribute:

audioObject.loop

Set the loop attribute:

audioObject.loop = true|false

Attribute Value

Value Description
true|false

Specify whether the audio should restart playing each time it finishes.

  • true - Indicates that the audio should restart playback after completion
  • false - Default. Indicates that the audio should not restart playback after the end

Technical Details

Return Value: Boolean value, returns true if the audio restarts playback at the end of each play. 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> loop Attribute