1. Home
  2. Computing & Technology
  3. Web Design / HTML

How To Add Background Music to Your Web Page

By Jennifer Kyrnin, About.com

Adding background music to a Web page can be very challenging, especially if you want to stay compliant with XHTML. In fact, the compliant method works in Netscape and Mozilla, but not in Internet Explorer. This document will teach you how to use both valid and invalid methods to add background sound.

Difficulty: Hard
Time Required: 10 minutes

Here's How:

  1. Valid Method First make sure that your document has an XHTML doctype listed as the first tag on the page (Note: The » symbol indicates a line wrap, delete both the character and the carriage return from your code.):
    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/ »
    xhtml1-transitional.dtd">
  2. Find a location on your page where you would want controls to appear.
  3. Add in an object tag:
    <object data="soundfile.mid" codetype="audio/mid"> </object>
    Change "soundfile.mid" to the midi you want to play. If you change it to a wav or other audio file, change the codetype as well.
  4. Save your page and upload both the page and the sound file.
  5. Invalid IE Method For this method, you don't need a valid doctype.
  6. Inside the <body> element, place a bgsound tag:
    <bgsound loop="0" src="basdanse.mid" />
    Change "soundfile.mid" to the sound file you want to play.
  7. Save your page and upload both the page and the sound file.

Tips:

  1. I strongly recommend you consider avoiding automatic playing sound on your Web pages. It can be very annoying and drive customers away.
  2. If you must have background sound, use the valid XHTML, unless you know that the customers you want to reach use Internet Explorer.
More Web Design / HTML How To's

Explore Web Design / HTML

More from About.com

  1. Home
  2. Computing & Technology
  3. Web Design / HTML
  4. Web Design
  5. Multimedia
  6. Sound
  7. How to Add Background Music to Your Web Page

©2008 About.com, a part of The New York Times Company.

All rights reserved.