HTML <audio> tag

Updated: 11/13/2018 by Computer Hope
HTML audio tag

When writing in HTML, the <audio> tag is an inline element used to embed sound files into a web page. It is useful when you want to add any audio, such as a song or interview, to your web pages. The following sections contain information about this tag, including an example of it in use, and related attributes and browser compatibility.

Example code

<audio controls="controls">
Your browser does not support the &lt;audio&gt; tag. <source src="https://www.computerhope.com/jargon/m/example.mp3" />
</audio>

The above code, rendered in a web browser:



File formats and browser support

When utilizing the <audio> tag, you need to ensure the sound file is in the proper format. There are three accepted formats which include MP3, Ogg, and WAV. The table below shows which Internet browsers support which file format.

Browser MP3 Ogg WAV
Chrome Yes Yes Yes
Internet Explorer Yes No No
Firefox Yes Yes Yes
Safari Yes No Yes
Opera Yes Yes Yes

Attributes

Within an HTML tag, an attribute dictates certain aspects of an HTML element. Attributes are made up of a name and value pair; all tags support standard attributes. The following table shows all of the current unique HTML attributes for the <audio> tag, and a description of each.

Attribute Description
autoplay Designates that the audio file will play immediately after it loads.
controls Designates what controls to display with the audio player.
loop Designates that the audio file should continuously repeat.
muted Designates that the audio file should be muted.
preload Designates how and when the audio file should load.
src Designates the URL of the audio file.

Compatibility

Edge Internet Explorer Firefox Safari Opera Chrome
9.0+ 8.0+ 3.5+ 4.0+ 10.5+ 4.0+

Browser, Compatibility, Container tag, Loop, Mute, Web design terms, Web page