Tag Description
The audio tag is used to define sound, such as music or other audio streams.
This tag has the form:
<audio
autoplay="autoplay"
controls="controls"
loop="loop"
muted
preload="auto | metadata | none"
src="URL">
fallback_content
</audio>
Note: The optional fallback_content is rendered by browsers that do not support the audio tag.
The MIME types for the HTML5 audio formats are:
- MP3 = audio/mpeg
- Wav = audio/wav
- Ogg = audio/ogg
HTML5 and HTML4.01 Differences
This tag is new for HTML5.
Attributes
Attribute | Value | Description |
---|---|---|
autoplay | autoplay | If present, specifies that the audio will start playing as soon as it is ready |
controls | controls | If present, specifies that controls will be displayed (such as a play button) |
loop | loop | If present, specifies that the audio will start over again, every time it is finished |
muted | muted | Specifies that the audio output should be muted |
preload | auto
metadata none |
Specifies if the audio should be loaded when the page loads, or not. Ignored if autoplay is present. |
src | URL | Specifies the URL of the audio to play |
Global Attributes
This tag also supports the HTML Global Attributes.
Event Attributes
This tag also supports the HTML Event Attributes.
Examples
The following example shows the basic use of this tag:
<audio src="audio.ogg" controls="controls"> Audio element not supported</audio>
This examples makes use of the <source>
tag to provide the most flexibility for browser support::
<audio controls="controls "><source src="audio.ogg" type="audio/ogg" / > <source src="audio.wav" type="audio/wav" / > Audio element not supported </audio>
Browser Support
Codec | Chrome | Firefox | IE | Opera | Safari |
---|---|---|---|---|---|
MP3 | 6 | 9 | 5 | ||
Wav | 6 | 3.6 | 10.6 | 5 | |
Ogg | 6 | 3.6 | 10.6 |
Doctype Declaration Support
The following table lists the doctype declarations this element may appear in:
HTML4.01 / XHTML1.0 | XHTML 1.1 | HTML 5 | ||
---|---|---|---|---|
Traditional | Strict | Frameset | ||
Miscellaneous Information
Defined In: | HTML5 |
---|---|
Empty Tag: | No |