Quackit Logo
HTML
CSS
Scripting
Database
Hosting
Design
XML

Print Version

HTML Background Music Code

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?

  • Share
  • Add this page to your Favorites
  • Link to this page (copy/paste into your own website or blog):
  • Link to Quackit using one of these banner ads.
  • Help support Quackit by making a donation

Oh, and thank you for supporting Quackit!

© Copyright 2000 - 2010 Quackit.com