HTML Tutorial 13

Prepared by: Anthony Larrain


Adding Audio

Method 1

Can use the anchor tag, <a> along with the href attribute to point to a sound file.

Example 1

Suppose you have an audio file called cielito.mp3 in a sub directory of my HTML file called sound. The following piece of code will link to the audio file.

<a href="sound/cielito.mp3">cielito.mp3</a>

Browser Display

cielito.mp3

Method 2

Example 2

<embed src="sound/cielito.mp3" />

Browser Display

Embed tag Attributes

Attribute Values Purpose
width a number Defines the width of the player in pixels.
height a number Defines the height of the player in pixels.
autostart true or false Specifies if the sound will play automatically, autostart="true" or not, autostart="false".
loop true or false Specifies if the sound should keep playing, loop="true" or play once, loop="false".
type MIME type Specifies the type of media player. For audio, type="audio/midi".
hspace a number Specifies the horizontal space around the player.
vspace a number Specifies the vertical space around the player.

Example 3

<embed src="sound/cielito.mp3" width="100" height="40" autostart="false" loop="true" type="audio/midi"></embed>

Browser Display

Design Tip

Make sure you always give the user the option to play the audio NOT the option to turn it off.

@Anthony Larrain 2005 - 2006

Send Questions or Comments to hci201@yahoo.com