Playing audio files

The audio element enables a simple way to play audio files in the browser. Adoption of this element had many controversial discussions mostly due to the lack of common grounds for a format. Initially Ogg Vorbis ( was the format suggested in the W3C specification.


Up-to-date information on browser support for different formats can be found on

In this recipe, we will take a look at the element and some of the basic attributes that can be applied on it.

Getting ready

In order to play an audio we need an actual audio file. You can pick one on your own or use the one that comes with the example. The file will be served from the music folder. We will use Mozart—Clarinet Concerto in A K. 622, ...

Get HTML5 Data and Services Cookbook now with O’Reilly online learning.

O’Reilly members experience live online training, plus books, videos, and digital content from 200+ publishers.