Skip to content

HTML autoplay Attribute

The HTML autoplay attribute is a boolean attribute and specifies that the audio or video will start playing automatically as soon as possible.

You can use this attribute on the following elements: <audio> and <video>.

Syntax

html
<tag autoplay>&lt;/tag&gt;

Note: Modern browsers restrict autoplay for media with audio tracks. To ensure autoplay works, you must also include the muted attribute on the element.

Example of the HTML autoplay attribute used on the <audio> element:

html
<!DOCTYPE html>
<html>
  <head>
    <title>Title of the document</title>
  </head>
  <body>
    <audio controls autoplay>
      <source src="https://www.w3docs.com/build/audios/jingle_bells.ogg" type="audio/ogg" />
      <source src="https://www.w3docs.com/build/audios/audio.mp3" type="audio/mpeg" />
    </audio>
    <p>Click the play button</p>
  </body>
</html>

Example of the HTML autoplay attribute used on the <video> element:

html
<!DOCTYPE html>
<html>
  <head>
    <title>Title of the document</title>
  </head>
  <body>
    <video width="320" height="240" controls autoplay muted>
      <source src="http://techslides.com/demos/sample-videos/small.ogv" type="video/ogg" />
      <source src="https://www.w3docs.com/build/videos/arcnet.io(7-sec).mp4" type="video/mp4" />
    </video>
    <p>Some information about video</p>
  </body>
</html>

Practice

What is the correct usage of the 'autoplay' attribute in HTML?

Dual-run preview — compare with live Symfony routes.