How to add background music in HTML?


The HTML <bgsound> tag is used to play music in the background. This tag is for Internet Explorer only.

Example

You can try to run the following code to add background music in HTML −

<!DOCTYPE html>
<html>
   <head>
      <title>HTML bgsound Tag</title>
   </head>
   <body>
      <bgsound src = "/html/yourfile.mdi"/>
      <p>Plays sound file in the background.</p>
   </body>
</html>

The HTML <bgsound> tag also supports the following attributes −

Attribute
Value
Description
loop
number
Lets you replay a background soundtrack a certain number of times.
src
URL
Specifies the path of the sound file.




Updated on: 24-Jun-2020

9K+ Views

Kickstart Your Career

Get certified by completing the course

Get Started
Advertisements