HTML5 provides a standard for playing audio files.
Before HTML5, there was no standard for playing audio files on a web page.
Before HTML5, audio files could only be played with a plug-in (like flash).
The HTML5 <audio> element specifies a standard way to embed audio in a web page.
Internet Explorer 9+, Firefox, Opera, Chrome, and Safari support the <audio> element.
Note: Internet Explorer 8 and earlier versions, do not support the <audio> element.
To play an audio file in HTML, use the <audio> element:
The controls attribute adds audio controls, like play, pause, and volume.
Text between the <audio> and </audio> tags will display in browsers that do not support the <audio> element.
Multiple <source> elements can link to different audio files. The browser will use the first recognized format.
Currently, there are 3 supported file formats for the <audio> element: MP3, Wav, and Ogg:
Browser | MP3 | Wav | Ogg |
---|---|---|---|
Internet Explorer | YES | NO | NO |
Chrome | YES | YES | YES |
Firefox | YES | YES | YES |
Safari | YES | YES | NO |
Opera | YES | YES | YES |
File Format | Media Type |
---|---|
MP3 | audio/mpeg |
Ogg | audio/ogg |
Wav | audio/wav |
HTML5 defines DOM methods, properties, and events for the <audio> element.
This allows you to load, play, and pause audios, as well as setting 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 HTML5 Audio/Video DOM Reference.
Tag | Description |
---|---|
<audio> | Defines sound content |
<source> | Defines multiple media resources for media elements, such as <video> and <audio> |