HTML <audio> Tag

Definition and usage

<audio> The tag is used to embed audio content in the document, such as music or other audio streams.

<audio> The tag can contain one or more elements with different audio sources <source> tag. The browser will choose the first source it supports.

<audio> and </audio> The text between tags will only be displayed in browsers that do not support <audio> element is displayed in the browser.

Tip:For video files, please see <video> tag.

HTML supports three audio formats: MP3, WAV, and OGG.

Audio formats and browser support

Browser MP3 WAV OGG
Edge / IE Supported Supported * Supported *
Chrome Supported Supported Supported
Firefox Supported Supported Supported
Safari Supported Supported Not supported
Opera Supported Supported Supported

* Starting from Edge 79

See also:

HTML DOM Reference Manual:HTML Audio/Video DOM Reference Manual

Example

Play sound file:

<audio controls>
  <source src="song.ogg" type="audio/ogg">
  <source src="song.mp3" type="audio/mpeg">
  Your browser does not support the audio tag.
</audio>

Try it yourself

Attribute

Attribute Value Description
autoplay autoplay The audio will start playing immediately after it is ready.
controls controls It is specified that the audio controls (such as play/pause buttons, etc.) should be displayed.
loop loop The audio is set to restart at the end of each cycle.
muted muted Specifies that the audio output should be muted.
preload
  • auto
  • metadata
  • none
Specifies whether and how to load the audio when the page is loaded.
src URL Specifies the URL of the audio file.

Global Attributes

<audio> The tag also supports Global Attributes in HTML.

event attributes

<audio> The tag also supports Event Attributes in HTML.

Default CSS Settings

None.

Browser Support

The numbers in the table indicate the first browser version that fully supports this element.

Chrome Edge Firefox Safari Opera
Chrome Edge Firefox Safari Opera
4.0 9.0 3.5 4.0 11.5