HTML5Sound in HTML 5

Back back to the main Sound page

The Audio Tag

HTML 5 has added a new audio tag to enable playing sound in web pages. The latest versions of all the main browsers support most of the options that this tag provides. Here is an example of the audio tag (assuming that your browser supports it correctly!):

Once again, try looking at this page in a range of different browsers to see how the audio player looks. There are differences in the default visual appearance of the player between the browsers.

The mark up for this tag is:

<audio controls>
    <source src="ddppl-excert.ogg" type="audio/ogg">
    <source src="ddppl-excert.mp3" type="audio/mpeg">
</audio>

Notice that there are two sound files specified, each one encodes the same track, but in a different audio format - the browser should try each file in turn until it finds a format that it can play, and then play it.

There are a lot of options available for this tag, including support for events to interact with the user, which we look at briefly later. The W3Schools page provides a complete and detailed list of them.