The Wayback Machine - https://web.archive.org/web/20221130133218/https://www.geeksforgeeks.org/html-autoplay-attribute/
Skip to content
Related Articles

Related Articles

HTML | autoplay Attribute

Improve Article
Save Article
  • Last Updated : 31 May, 2022
Improve Article
Save Article

The HTML autoplay Attribute is used to specify that the audio/video should automatically start playing when web page is loaded. It is a Boolean attribute. 
Syntax: 
 

<element autoplay> 

Uses It can be used with <audio> and <video> element. 
Example 1: Here the autoplay attribute is used with the <video> tag. 
 

html




<!DOCTYPE html>
<html>
 
<head>
    <title>HTML video autoplay Attribute</title>
</head>
 
<body>
    <center>
        <h1 style="color:green;">GeeksforGeeks</h1>
 
        <h3>HTML video autoplay Attribute</h3>
 
        <video width="400" height="200" controls autoplay>
            <source src=
                    type="video/mp4">
            <source src=
                    type="video/ogg">
        </video>
    </center>
</body>
 
</html>

Output: 
 

Example 2: Here the autoplay attribute is used with the <audio> tag. 
 

html




<!DOCTYPE html>
<html>
 
<head>
    <title>
        HTML audio autoplay Attribute
    </title>
</head>
 
<body style="text-align: center">
 
    <h1 style="color: green">
        GeeksforGeeks
    </h1>
 
    <h2>HTML audio autoplay Attribute</h2>
 
    <audio controls autoplay>
        <source src=
                        type="audio/ogg">
        <source src=
                    type=" audio/mpeg ">
    </audio>
</body>
 
</html>       

Output: 
 

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

  • Google Chrome 3.0 and above
  • Internet Explorer 9.0
  • Firefox 3.5 and above
  • Safari 3.1 and above
  • Opera 10.5 and above
  • Edge 12 and above

 


My Personal Notes arrow_drop_up
Related Articles

Start Your Coding Journey Now!