Home > Abakada: Back to Basics > Language References > HTML Elements > AUDIO Element
Embeds audio content in an HTML document. | HTML 5 |
HTML Syntax
<audio
autoplay
crossorigin = anonymous | use-credentials
controls
loop
muted
preload = auto | metadata | none
src = url
>
<source ... />
<track ... />
/<audio
NOTE: Both start and end tags are required.
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.
<audio src="music.mp3" ...></audio>
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>
The <audio>
element supports the following attributes, in addition to global attributes common to all HTML elements.
autoplay | autoplay | Specifies that the audio will start playing as soon as it is ready |
controls | controls | Specifies that audio controls should be displayed (such as a play/pause button etc) |
loop | loop | 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 and how the author thinks the audio should be loaded when the page loads |
src | URL | Specifies the URL of the audio file |
The following example shows how the <audio
> element may be used.
<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 PICTURE SOURCE VIDEO