HTML5 Audio

HTML5 provides audio element to embed audio in web page. Prior to HTML5, we are using third party plug-ins, like - flash, Window Media Center, Apple iTunes, etc to play audio on the browser. The problem with these plug-ins are that, not all browsers or devices support it. HTML5 provides a standard way to include audio with several attributes which improve its default behaviour.

It is very easy to embed audio in an HTML5 document.

Example

<audio controls="controls">
<source src="audio/audio.mp3" type="audio/mpeg" />
<source src="audio/audio.wav" type="audio/wav" />
<source src="audio/audio.ogg" type="audio/ogg" />	
Your browser does not support the embedded HTML5 audio element.
</audio> 



The text enclosed within the <audio> element will appear in only those browsers which do not support <audio> element.

Attributes of AUDIO element

Attribute Name Description
controls It specifies audio control units like Play, Pause, Volume controls.
autobuffer The audio will automatically continue buffering.
loop It repeats the audio play over and over again without stopping.
autoplay The audio will automatically play once the web page has loaded.
source It contain different types of audio formats to support in different browsers and devices.
type It specifies MIME type of the audio, like- mp3, wav, ogg.




HTML5 audio media types

Format Type
MP3 MP3 is MPEG Audio Layer 3. It is best known compressed digital audio file.
WAV It is uncompression audio format owned by google. It uses the VP8 codac.
Ogg It is a free open source audio compression format.







Read more articles


General Knowledge



Learn Popular Language