HTML5 Audio (Audio)


HTML5 provides a standard for playing audio files.


Internet Media

There is no standard yet for playing audio on the web.

Currently, most audio is played through plugins (like Flash). However, not all browsers have the same plugins.

HTML5 specifies a standard for embedding audio elements in web pages, using the <audio> element.


Browser Support

Internet ExplorerFirefoxOperaGoogle ChromeSafari

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.


HTML5 Audio - How It Works

To play audio in HTML5, you need to use the following code:

Instance

<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>

Try this »

The control attribute is used to add play, pause, and volume controls.

Between the <audio> and </audio> tags, you need to insert the audio element's fallback text that the browser does not support.

The <audio> element allows multiple <source> elements. The <source> element can link to different audio files, and the browser will use the first supported audio file.


Media Formats and Browser Support

Currently, the <audio> element supports three audio format files: MP3, Wav, and Ogg:

Browser MP3 Wav Ogg
Internet Explorer 9+ YES NO NO
Chrome 6+ YES YES YES
Firefox 3.6+ YES YES YES
Safari 5+ YES YES NO
Opera 10+ YES YES YES


MIME Types for Audio Formats

Format MIME-type
MP3 audio/mpeg
Ogg audio/ogg
Wav audio/wav


HTML5 Audio Tag

Tag Description
<audio> Defines audio content
<source> Specifies multimedia resources that can be multiple, used in <video> and <audio> tags
Other Extensions