HTML5 Audio


HTML5 provides a standard for playing audio files.


Audio on the Internet

Until now, there is still no standard for playing audio on web pages.

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

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


Browser Supports

Internet Explorer Firefox Opera Google Chrome Safari

Internet Explorer 9+, Firefox, Opera, Chrome, and Safari all support the <audio> element.

Note: Internet Explorer 8 and earlier versions of IE do not support the <audio> element.


HTML5 Audio - How It Works

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

Example

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

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

Between <audio> and </audio> you need to insert the prompt text of the <audio> element that the browser does not support.

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


Audio Format and Browser Supports

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

BrowserMP3WavOgg
Internet Explorer 9+YESNONO
Chrome 6+YESYESYES
Firefox 3.6+YESYESYES
Safari 5+YESYESNO
Opera 10+YESYESYES



MIME Type of The Audio Format

FormatMIME-type
MP3audio/mpeg
Oggaudio/ogg
Wavaudio/wav



HTML5 Audio Tags

LabelDescription
<audio>Defined sound content
<source>Specifies multimedia resources, which can be multiple, used in the <video> and <audio> tags