Advertisement
Home Open Editor ❯

HTML <audio> autoplay Attribute

Example

<audio controls autoplay>
  <source src="cat.mp3" type="audio/mpeg">
  <source src="cat.ogg" type="audio/ogg">
  Your browser does not support the audio tag.
</audio>

Try this code ❯

Meaning

The autoplay attribute indicates the browser should playing the audio as soon as after page load once it has loaded enough of the audio to avoid buffering.

Note: Some browsers do not allow autoplay in most of the cases. However, muted autoplay is always allowed.

Sites that automatically play audio (or videos with an audio track) can be an unpleasant experience for users, so should be avoided when possible.

If you must offer autoplay functionality, you should make it opt-in (requiring a user to specifically enable it).

However, this can be useful when creating media elements whose source will be set at a later time, under user control.


Standard Syntax

<audio autoplay>
  <source src="Source(URL)" type="mediaType">
  Your browser does not support the audio tag.
</audio>


Advertisement

Attribute Values

Value Description
autoplay This is a boolean attribute, the presence of a boolean attribute on an element represents the true value, and the absence of the attribute represents the false value.
Home Open Editor ❯
Advertisement