HTML Audio Tag

HTML audio tag is used to define sounds such as music and other audio clips. Currently, there are three supported file formats for HTML 5 audio tag.

HTML audio tag is used to define sounds such as music and other audio clips. Currently, there is three supported file format for HTML 5 audio tag.

  1. mp3
  2. wav
  3. ogg

HTML5 supports <video> and <audio> controls. The Flash, Silverlight and similar technologies are used to play multimedia items.

This table defines which web browser supports which audio file format.

Browser mp3 wav ogg
ie browser Internet Explorer yes no no
chrome browser Google Chrome yes yes yes
firefox browser Mozilla Firefox yes* yes yes
opera browser Opera no yes yes
safari browser Apple Safari yes yes no

HTML Audio Tag Example

Let's see the code to play the mp3 file using HTML audio tag.

 

<audio controls>  

  <source src="koyal.mp3" type="audio/mpeg">  

Your browser does not support the html audio tag.  

</audio>  

 

Output:

Let's see the example to play ogg file using HTML audio tag.

 

<audio controls>  

  <source src="koyal.ogg" type="audio/ogg">  

Your browser does not support the html audio tag.  

</audio>  


Supporting Browsers

Element chrome browser Chrome ie browser IE firefox browser Firefox opera browser Opera safari browser Safari
<audio> Yes Yes Yes Yes Yes

 

Attributes of HTML Audio Tag

There is given a list of HTML audio tag.

Attribute Description
controls It defines the audio controls which are displayed with play/pause buttons.
autoplay It specifies that the audio will start playing as soon as it is ready.
loop It specifies that the audio file will start over again, whenever it is completed.
muted It is used to mute the audio output.
preload It specifies the author's view to upload an audio file when the page loads.
src It specifies the source URL of the audio file.

HTML Audio Tag Attribute Example

Here we are going to use controls, autoplay, loop and src attributes of HTML audio tag.

 

<audio controls autoplay loop>  

  <source src="koyal.mp3" type="audio/mpeg"></audio>  

 


MIME Types for HTML Audio format

The available MIME types HTML audio tag is given below.

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