How to autoplay audio on chrome ?

Here we will learn how to auto-play audio on selected devices in web pages. To load the audio in the web page, we use the <audio> tag.

There are some attribute of this “audio” tag:

  • controls: This feature is used for audio be visible the controls on the web pages. After using this feature, we can pause or play music, high or low music.
  • autoplay: This feature is used for audio to start audio clip when page load. If you run a web page, the audio file will load and just the audio will play automatically.

Example:

filter_none

edit
close

play_arrow

link
brightness_4
code

<!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="GFG.ogg" type="audio/ogg"
        <source src="GFG.mp3" type="audio/mpeg"
    </audio
</body
  
</html>

chevron_right


Output:

full-stack-img

My Personal Notes arrow_drop_up

Check out this Author's contributed articles.

If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to contribute@geeksforgeeks.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.

Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.


Article Tags :
Practice Tags :


4


Please write to us at contribute@geeksforgeeks.org to report any issue with the above content.