The HTML <audio></audio> element is used to embed sound content in an HTML or XHTML document. It was first introduced in HTML5 and Gecko 1.9.1. Typically only .mp3, .wav, and .ogg files are accepted.


Attribute Value Description
autoplay Boolean A Boolean attribute. If specified, the audio will automatically begin to play back as soon as it can without stopping to finish loading the data.
autobuffer Boolean A Boolean attribute. If specified, the audio will automatically begin being downloaded, even if not set to automatically play. This continues until the media cache is full, or the entire audio file has been downloaded, whichever comes first. This should only be used when it is expected that the user will choose to play the audio; for example, if the user has navigated to a page using a "Play this audio" link.
controls Boolean If this attribute is present, the browser will offer controls to allow the user to control audio playback, including volume, seeking, and pause/resume playback.
loop Boolean A Boolean attribute. If specified, it will, upon reaching the end of the audio, automatically seek back to the start.
src URL The URL of the audio to embed. This is subject to HTTP access controls. This is optional; you may instead use the <source> element within the audio block to specify the audio to embed.

HTML example 1:

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

HTML example 2:

<audio controls>
<source src="whatever.ogg" type="audio/ogg" />
<source src="whatever.mp3" type="audio/mpeg" />

When you view the webpage containing this element, you will either hear the sound file, or you will see text saying that your browser does not support this element. An audio example can be found below. Click on it to listen to it. Imagine this page has that sound as its bg music.

Audio Example

See Also

Community content is available under CC-BY-SA unless otherwise noted.