Share
How It Works
To play an audio file in HTML5, this is all you need:
<audio src="song.ogg" controls="controls">
</audio>
The control attribute is for adding play, pause, and volume controls.
Insert content between the <audio> and </audio> tags for browsers that do not support the audio element:
<audio src="song.ogg" controls="controls">
Your browser does not support the audio element.
</audio>
The example above uses an Ogg file, and will work in Firefox, Opera and Chrome.
To make the audio work in Safari, the audio file must be of type MP3 or Wav.
The audio element allows multiple source elements. Source elements can link to different audio files. The browser will use the first recognized format:
<audio controls="controls">
<source src="song.ogg" type="audio/ogg" />
<source src="song.mp3" type="audio/mpeg" />
Your browser does not support the audio element.
</audio>