HTML Audio
HTML <audio> Element
The HTML <audio> element is used to play an
audio file on a web page.
It supports playback controls like play, pause, and volume.
Example
The HTML code:
<audio controls>
<source src="horse.ogg" type="audio/ogg">
<source src="horse.mp3" type="audio/mpeg">
Your browser does not support the audio element.
</audio>
Result
HTML <audio> Attributes
The controls attribute adds audio controls, like play, pause, and volume.
The <source> element allows you to specify alternative audio
files which the browser may choose from. The browser will use the first recognized format.
The text between the <audio> and </audio> tags will only be displayed
in browsers that do not
support the <audio> element.
HTML <audio> Autoplay
To start an audio file automatically, use the autoplay attribute:
Example
<audio controls autoplay>
<source src="horse.ogg" type="audio/ogg">
<source src="horse.mp3" type="audio/mpeg">
Your browser does not support the audio element.
</audio>
Try it Yourself »
Add muted after
autoplay to let your audio file start playing automatically (but muted):
Example
<audio controls autoplay muted>
<source src="horse.ogg" type="audio/ogg">
<source src="horse.mp3" type="audio/mpeg">
Your browser does not support the audio element.
</audio>
Try it Yourself »
Supported Audio Formats in HTML5
The supported audio formats in HTML are:
| Video Format | File Extension | Media Type |
|---|---|---|
| MP3 | .mp3 | audio/mpeg |
| Ogg | .ogg | audio/ogg |
| WAV | .wav | audio/wav |
HTML Audio - Methods, Properties, and Events
The HTML DOM defines methods, properties, and events for the <audio> element.
This allows you to load, play, and pause audios, as well as set duration and volume.
There are also DOM events that can notify you when an audio begins to play, is paused, etc.
For a full DOM reference, go to our HTML Audio/Video DOM Reference.
HTML Audio Tags
| Tag | Description |
|---|---|
| <audio> | Defines sound content |
| <source> | Defines multiple media resources for media elements, such as <video> and <audio> |