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

<tag autoplay></tag>

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

<!DOCTYPE html>
<html>
  <head>
    <title>Title of the document</title>
  </head>
  <body>
    <audio controls autoplay>
      <source src="/build/audios/jingle_bells.ogg" type="audio/ogg">
      <source src="/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:

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



Do you find this helpful?

Related articles