HTML autoplay Attribute

Last Updated : 29 May, 2026

The HTML autoplay attribute automatically starts playing media as soon as it is ready. It is commonly used with audio and video elements to begin playback without user interaction.

  • Automatically plays media when the page loads or the media is ready.
  • Can be used with both <audio> and <video> elements.
  • Often combined with other attributes such as muted, loop, and controls.

Syntax: 

<element autoplay> 

Supported Elements

Here the supported elements:

  • <audio>: <audio> embeds audio content in a webpage.
  • <video>: <video> embeds video content in a webpage.

HTML Video autoplay

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.

html
<!--Driver Code Starts-->
<!DOCTYPE html>
<html>

<head>
    <title>
        HTML video autoplay Attribute
    </title>
</head>

<body>
    <center>
        <h3>HTML video autoplay Attribute</h3>
<!--Driver Code Ends-->

        <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>

<!--Driver Code Starts-->
    </center>
</body>

</html>
<!--Driver Code Ends-->

HTML Audio autoplay

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.

html
<!--Driver Code Starts-->
<!DOCTYPE html>
<html>

<head>
    <title>
        HTML audio autoplay Attribute
    </title>
</head>

<body>
    <h2>HTML audio autoplay Attribute</h2>
<!--Driver Code Ends-->

    <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>

<!--Driver Code Starts-->
</body>

</html>
<!--Driver Code Ends-->
Comment