Embedding Audio in HTML 5 Pages

HTML5 supports audio tag which is used to embed sound content in an HTML or XHTML document as follows.

<audio src="foo.wav" controls autoplay>
    Your browser does not support the <audio> element.   
</audio>

The current HTML5 draft specification does not specify which audio formats browsers should support in the audio tag. But most commonly used audio formats are ogg, mp3 and wav.

You can use source tag to specify media along with media type and many other attributes. An audio element allows multiple source elements and browser will use the first recognized format:

<!DOCTYPE HTML>
<html>
<body>
   <audio controls autoplay>
       <source src="/html5/audio.ogg" type="audio/ogg" />
       <source src="/html5/audio.wav" type="audio/wav" />
       Your browser does not support the <audio> element.
   </audio>
</body>
</html>

Enjoyed this post? Share it!

 

Leave a comment

Your email address will not be published.