Quackit Logo

Got a MySpace Page?

Get "www.yourname.com" for your MySpace page. Learn how >>.

HTML Background Music Code

Print Version

You can add HTML background music code to your web page using the hidden attribute of the embed tag. The embed tag isn't actually part of the HTML specification but it is still widely supported by the major browsers.

Example Background Music Code

<embed name="lostmojo"
src="/web_design/lostmojo.wav"
loop="false"
hidden="true"
autostart="true">
</embed>

This code will run music in the background as soon as the page loads. See/hear the result.

Adding Audio Controls

If you want your users to be able to control whether the background music plays or not, you can simply remove the hidden attribute (or change it to "false"). You can also add width and height to the controls. It's also a good idea to turn autostart off (autostart="false").

<embed name="lostmojo"
src="/web_design/lostmojo.wav"
loop="false"
width="300"
height="90"
hidden="false"
autostart="false">
</embed>

This results in:

Have you checked out the HTML Tutorial?

Enjoy this website?

  1. Link to this page (copy/paste into your own website or blog):
  2. Add this page to your favorite social bookmarks sites:
                     
  3. Add this page to your Favorites

Oh, and thank you for supporting Quackit!