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.
Browser Display
Method 2
- Using the
<embed>
tag along with thesrc
attribute. - The
embed
tag will embed an object into your webpage. Also called a control panel. - For audio it will display a small player.
- The
embed
tag is an empty tag.
Example 2
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
Browser Display
Design Tip
Make sure you always give the user the option to play the audio NOT the option to turn it off.