Language References
Embeds audio content in an HTML document. | HTML 5 |
HTML Syntax
<audio
autoplay
controls
loop
muted
preload = auto | metadata | none
src = url
event = script
>
The AUDIO element is used to embed sound content in an HTML document, without requiring any third-party plug-in or involve complex scripting.
In its simplest form, the src attribute is required, which specifies the location of the audio file to embed.
Alternatively, authors can use the SOURCE element, as it allows for multiple alternative options.
A <source
> tag specifies an audio file, which can be any of three supported audio formats in HTML: MP3, WAV, and OGG.
The <source
> tags are defined as child elements of the <audio
>...</audio
> tag.
<audio ...>
<source src="music.mp3" ...>
<source src="music.ogg" ...>
</audio>
The browser plays the first source it supports.
A download link or some “fallback” text can be defined within the <audio
>...</audio
> tags, to provide alternate content in cases where the browser does not support the AUDIO element or the audio content, or somehow failed to download the audio source file.
<audio src="music.mp3" ...>
Sorry, your browser does not support audio playback.
http://somewhere.com/media/music.mp3
</audio>
NOTE: Both start and end tags are required.
The <audio
> element supports the following attributes, in addition to global attributes common to all HTML media elements.
Attribute | Value | Description |
autoplay | autoplay | Specifies whether the audio will automatically start playing as soon as it can do so. |
controls | controls | Specifies whether to display audio controls that allow users to play/stop audio, adjust/mute volume, etc. |
loop | loop | Specifies whether the audio will automatically start over again, upon reaching the end. |
muted | muted | Specifies whether the audio ouput is silenced. |
preload | auto | metadata | none | Specifies if and how the author thinks the audio should be loaded when the page loads. Setting autoplay overrides this attribute. |
src | URL | Required. Specifies the location of the audio file to embed. |
<audio controls>
<source src="happy-day.mp3" type="audio/mpeg">
Sorry, your browser does not support the audio element.
</audio>
which would render on a Web page as follows:
EMBED OBJECT VIDEO