The HTML autoplay Attribute, a boolean attribute, enables audio or video elements to start playing automatically when the page loads, providing seamless playback without interruption.
Syntax:Â
<element autoplay> Supported Elements
It can be used with <audio> and <video> elements.Â
| Element | Description |
|---|---|
<audio> | Embeds audio content in a webpage. |
<video> | Embeds video content in a webpage. |
HTML Video autoplay Code Example
In this example we demonstrates the use of the autoplay attribute for the <video> element, enabling automatic playback of the video when the page loads.
<!DOCTYPE html>
<html>
<head>
<title>
HTML video autoplay Attribute
</title>
</head>
<body>
<center>
<h3>HTML video autoplay Attribute</h3>
<video width="400" height="200" controls autoplay>
<source src=
"https://media.geeksforgeeks.org/wp-content/uploads/20190616234019/Canvas.move_.mp4"
type="video/mp4" />
<source src=
"https://media.geeksforgeeks.org/wp-content/uploads/20190616234019/Canvas.move_.ogg"
type="video/ogg" />
</video>
</center>
</body>
</html>
Output:Â

HTML Audio autoplay Code Example
In this example we demonstrates the use of the autoplay attribute for the <audio> element, enabling automatic playback of the audio when the page loads.
<!DOCTYPE html>
<html>
<head>
<title>
HTML audio autoplay Attribute
</title>
</head>
<body>
<h2>HTML audio autoplay Attribute</h2>
<audio controls autoplay>
<source src=
"https://media.geeksforgeeks.org/wp-content/uploads/20190531165842/Recording1514.ogg"
type="audio/ogg" />
<source src=
"https://media.geeksforgeeks.org/wp-content/uploads/20190531165842/Recording1514.mp3"
type=" audio/mpeg " />
</audio>
</body>
</html>
Output:Â

Supported Browsers: The browser supported by HTML autoplay attributes are listed below:Â