How to add background music in HTML


In this article, I will explain how to add background music in HTML File with the help of embed tag and repeatation of music at the background. It is used to play the music automatically by setting autostart attribute to true of embed tag. Play button is hidden using hidden attribute to hide the control so that the music control can be hidden from the user. It enables to repeat the music by setting the loop value to true.

In this article, Lets see detail description about Embed tag. It is used to play the music automatically by setting autostart attribute. Play button is hidden using hidden attribute to hide the control so that the music control can be hidden from the user. It enables to repeat the music by setting the loop value to true. Volume of the music can be control by setting value to the volume attribute.

Adding following code in html file will embed music in html page

 
<embed src="sample.mp3" autostart="true" hidden="true"
loop="true" volume="10"/>


src is the destination of the music file. Setting URL of resource to be embedded

autostart is used to run the music once. Setting Boolean true enables to start the music while loading the page whereas false will not start the music at the beginning of the html page.

hidden is used to hide the control. Setting boolean true enables to hide the control whereas false enables to visible the control.
loop is used to repeat the music. Setting boolean true value enable to repeat the music whereas false will not repeat the music.

volume is how loud to play the sound. Setting value to volume will increase or decrease the volume of the music.

Find sample.html and sample.mp3 files for you reference.

Below is the sample code of the html file.

 
<html>
<head>
<title>
Music in HTML
</title>
</head>
<body>
<embed src="sample.mp3" autostart="true" hidden="true" loop="true" volume="10"></embed>
<B>Sample HTML file for embedding Music</B>
</body>
</html>


Attachments

  • sample.html for embedding music to html (44145-31233-sample.html-embedding-music-html.html)
  • sample.mp3 file for embedding music to html (44145-31523-sample.mp3-file-embedding-music-html.mp3)
  • Comments

    No responses found. Be the first to comment...


  • Do not include your name, "with regards" etc in the comment. Write detailed comment, relevant to the topic.
  • No HTML formatting and links to other web sites are allowed.
  • This is a strictly moderated site. Absolutely no spam allowed.
  • Name:
    Email: