Audio HTML

HTML <audio> Tag

To specify sounds (music and other audio clips), the HTML <audio> tag is used. Three types of file format are supported for HTML 5 audio tag currently. These are mp3, wav and ogg. Both the <video> and <audio> controls are supported in HTML 5. To play the multimedia items, technologies like Flash, Silverlight and other similar technologies are used.

Supported audio file format:

Browser mp3 wav ogg
Internet Explorer Yes No No
Chrome Yes Yes Yes
Firefox Yes Yes Yes
Opera No Yes Yes
Safari Yes Yes No

Example 1:

<!DOCTYPE html>
<html>
<body>
<p>Play the Audio.</p>
<audio controls>
<source src="peacock.mp3" type="audio/mpeg">
This browser does not support the audio element.
</audio>
</body>
</html>

Output:

Explanation:

In the above example, we are playing an mp3 file using HTML audio tag.

Example 2:

<!DOCTYPE html>
<html>
<body>
<p>Play the Audio.</p>
<audio controls>
<source src="peacock.ogg" type="audio/ogg">
This browser does not support the audio element.
</audio>
</body>
</html>

Output:

Explanation:

In the above example, we are playing an ogg file using HTML audio tag.

Supporting Browsers:

Chrome, IE, Firefox, Opera and Safari.

Attributes of HTML <audio> Tag:

Attribute Uses
controls Used to specify the audio controls and is displayed with play/pause buttons.
autoplay Used to specify that the audio is on autoplay mode.
loop Used to start the audio file over and over again, every time when it is completed.
muted Used to mute the audio output.
preload Used to specify the author view to load the audio file when the page loads.
src Used to specify the URL of the audio file to add.

 

Example 3:

<!DOCTYPE html>
<html>
<body>
<p>Play the Audio.</p>
<audio controls autoplay loop>
<source src="peacock.mp3" type="audio/mpeg">
This browser does not support the audio element.
</audio>
</body>
</html>

Output:

Explanation:

In the above example, we are playing an mp3 file using controls, autoplay, loop and src attributes of HTML audio tag.

MIME types for HTML <audio> tag:

Audio Format MIME Type
mp3 audio/mpeg
ogg audio/ogg
wav audio/wav
Please Share