Computer >> Computer tutorials >  >> Programming >> HTML

How to play sound file in a web-page in the background?


The HTML <audio> element is used to add audio to web page. To play sound file in the background on a web page, use the <embed>…</embed> element. Also, use the autoplay attribute. This will run music in the background whenever the page loads.

Set the width and height in a way the player hides on the web page. The loop attribute is added to specify whether the audio will start over again.

How to play sound file in a web-page in the background?

You can try to run the following code to play a sound file in a web page in the background

Example

<!DOCTYPE html>
<html>
   <head>
      <title>HTML background music</title>
   </head>
   <body>
      <p>The music is running in the background.</p>
      <p>(Song: Kalimba which is provided as a Sample Music in Windows)</p>
      <embed src="/html/Kalimba.mp3" loop="true" autostart="true" width="2"
         height="0">
   </body>
</html>