How to Add Background Music to Your Web Page
by Christopher Heng, thesitewizard.com
If you code your web pages using a text editor (as opposed to using one of those specialized web editors that give you a toolbar button for everything), you may be wondering how you might go about adding background music to your web pages. While this is not a question I encounter often at thesitewizard.com, I do get the occasional music aficionado sending me this query, hence this article.
Issues Surrounding Background Music
Before you start, you should be aware that background music that automatically starts playing when a web page is loaded may not be appreciated by a large number of your visitors. Some of them, when greeted with the sudden blaring of music from their speakers, may immediately hit the BACK button of their browsers. This may occur even if you're playing a piece of music that you think is well loved by everyone: remember, there are people who surf the Internet in public libraries, at work, or in the dead of the night when others are asleep. Others may already have their favourite piece of music playing on their computer speakers, and your auto-playing music file will only cause them to be annoyed.
Even if you are satisfied that your website has the type of target audience that will enjoy your background music, there are alternatives to automatically playing music that you might want to consider. For example, giving visitors a link which they can click to play music would allow you to showcase your music while remaining sensitive to your visitors' preferences. Instructions on how to accomplish this, as well as how to implement autoplaying music, are given below.
Playing Music Only When a Link is Clicked
If you have a MIDI file that you want played when a visitor clicks a link, put HTML code like the following on your page:
Play background music
Replace the "yourmusicfile.mid" with the appropriate filename. Note that the above HTML code works for ".wav" and ".mp3" files as well (or anything else for that matter).
How to Embed Background Music on Your Web Site
The problem with embedding background music is that the different browsers out there have their own methods of implementing embedded music files.
For all versions of Netscape, as well as IE 3.0 and above, you can use the following code: