Audio

The <audio> element lets you play sound on your site. You do so by writing:

<audio src="path/to/audio.mp3" controls>
    <p>Your browser doesn't support the HTML5 audio element.</p>
</audio>

As with the <video> element, the <audio> element also takes the attributes src and controls, and they behave exactly the same. The src is the path to the file, and controls display the controls, allowing the user to play and pause the audio, and control the audio.

If you need a fallback audio, you can use the `<source>` element. You would then write:

<audio controls>
    <source src="path/to/audio.mp3" type="audio/mp3">
    <source src="path/to/audio.oog" type="audio/oog">
    <p>Your browser doesn't support the HTML5 audio element.</p>
</audio>

As of February 2016, the following browser support these video formats:

Browser

MP3

Wav

Ogg

Internet explorer

Yes

No

No

Chrome

Yes

Yes

Yes

Firefox

Yes

Yes

Yes

Safari

Yes

Yes

No

Opera

Yes

Yes

Yes

Microsoft Edge

Yes

Yes

No

Other notable attributes are autoplay, loop and muted. These are all the same as with their video counterpart. autoplay starts the audio automatically, loop seeks back to the start of the audio when it reaches the end, and muted sets the default volume to silenced.

You can read more about the audio element here.

Last updated