Easy Tutorial
❮ Html Tables Html5 Form Input Types ❯

HTML5 Audio(Audio)


HTML5 provides a standard for playing audio files.


Audio on the Internet

Until now, there has been no standard for playing audio on web pages.

Today, most audio is played through plugins (such as Flash). However, not all browsers have the same plugins.

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


Browser Support

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.


How HTML5 Audio Works

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

Example

&lt;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>

The control attribute adds play, pause, and volume controls.

Between <audio> and </audio>, you need to insert a prompt text for browsers that do not support the <audio> element.

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.


Audio Formats and Browser Support

Currently, the <audio> element supports three audio formats: 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 Tags

Tag Description
<audio> Defines sound content
<source> Specifies multimedia resources, which can be multiple, used within <video> and <audio> tags
❮ Html Tables Html5 Form Input Types ❯