Horje
HTML autoplay Attribute

Definition and Usage

The autoplay attribute is a boolean attribute.

When present, the audio/video will automatically start playing as soon as it can do so without stopping.


Applies to

The autoplay attribute can be used on the following elements:

Elements Attribute
<audio> autoplay
<video> autoplay

Browser Support

The autoplay attribute has the following browser support for each element:

 


How to add An audio file that will automatically start playing

The audio autoplay attribute. Click on the play button to play a sound.
index.html
Example: HTML
<!DOCTYPE html>
<html>
<body>

<h1>The audio autoplay attribute</h1>

<p>Click on the play button to play a sound:</p>

<audio controls autoplay>
  <source src="https://samplelib.com/lib/preview/mp3/sample-3s.mp3" type="audio/ogg">
  <source src="https://samplelib.com/lib/preview/mp3/sample-3s.mp3" type="audio/mpeg">
  Your browser does not support the audio element.
</audio>

</body>
</html>

Output should be:

How to add An audio file that will automatically start playing

How to add A video that will automatically start playing in HTML Page

The video autoplay attribute.

index.html
Example: HTML
<!DOCTYPE html>
<html>
<body>

<h1>The video autoplay attribute</h1>

<video width="320" height="240" controls autoplay>
  <source src="https://www.sample-videos.com/video321/mp4/240/big_buck_bunny_240p_30mb.mp4" type="video/mp4">
  <source src="movie.ogg" type="video/ogg">
  Your browser does not support the video tag.
</video>

</body>
</html>

Output should be:

How to add A video that will automatically start playing in HTML Page




html autoplay attribute

Type:
Develop
Category:
Web Tutorial
Sub Category:
HTML Attribute
Uploaded by:
Admin


Read Article
https://develop.horje.com/learn/1434/reference