HTML <audio> tag

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

When writing in HTML (hypertext markup language), 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, 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 the three file formats.

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

All HTML tags support standard attributes that define the settings of an HTML element. In addition to the standard settings, the <audio> tag has the following unique attributes.

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 (uniform resource locator) 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