Quackit

This is the print version of http://www.quackit.com/html/html_music_code.cfm


HTML Music Codes (Print Version)

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

You can also check out the Music Code Generator.

How to embed an audio file

You can embed a music file into your page using the following HTML code:

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

This code will present a music console with the appropriate controls like this:

(If you don't see any music controls and don't hear any music, you may need to download a plugin for your browser.)

Need to create a music playlist?

You can make your music player loop through more than one song using a music playlist.

How to preload a sound file

You can preload music files so that the music starts immediately after the user has clicked on the link. You can preload using the following technique:

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

This embeds the sound, but the 'autostart' feature is off (you don't want to annoy the user now, do you?) and the 'hidden' feature is true, so the user doesn't see a console upon entering your webpage.

How to link to a music file

You can also link to a music file using the <a href= tag. All you need to do is write something like this:

Listen to a sample of <a href="/web_design/lostmojo.wav">Lost Mojo</a>

This obviously assumes that the music file is in the specified location.

© Copyright 2000 - 2010 Quackit.com