Login | Contact Us | Site Map | Resources

Other HTML Elements

Home > HTML Tutorial > HTML Music Codes

HTML Music Codes

HTML provides the <embed> tag as a method of embedding music in your HTML file. It is an empty element, meaning that it does not have a closing tag.

The "src", or source attribute points to the location and name of the file that is to be embedded. The file types supported by this element are MIDI (.mid), MP3 (.mp3) and WAV (.wav).

<embed src="http://www.phpforkids.com/music/file-name.mp3" />

You can control the size and other display aspects of the player that is embedded in your webpage.

width=""   Numeric Value Indicating the Width of the Player
height=""   Numeric Value Indicating the Height of the Player
hidden="true"   Hides the Play/Pause/Stop Controls
hidden="false"   Shows the Play/Pause/Stop Controls

Several additional attributes are available.

autostart="true"   Causes the Music to Play When Page Is Fully Loaded
autostart="false"   Prevents the Music From Playing Until "Play" Is Pressed
loop="true"   Loops/Repeats the Music Continuously
loop="false"   Loops/Repeats the Music Once
volume=""   Numeric Value (0-100) Controls the Starting Volume

Most visitors will not appreciate music being played on a webpage unless maybe they can immediately see a method of stopping it. Use this feature wisely (and sparingly)!