HTML audio Tag

HTML <audio> Tag: The <audio> tag describes the sound. The audio formats that  audio tag element supports are MP3, WAV and OGG. <audio> tag belongs to Flow Content category.

HTML <audio> Tag

This tag supports Global and event attributes. It was added newly to HTML5.

Syntax: <audio controls><source src=” ” type=” “>–content–</audio>

Browser compatibility

The <audio> tag is supported by different types of browsers.

  • Chrome-4.0
  • Firefox-3.5
  • Safari-4.0
  • InternetExplorer-9.0
  • Opera-10.5

Example:

<table class=" align left">
<tbody>
<tr>
    <th>Browser</th>
      <th>MP3</th>
      <th>WAV</th>
     <th>OGG</th>
</tr>
<tr>
        <td> Internet Explorer</td>
         <td> YES </td>
         <td> NO</td>
   <td> NO</td>
         </tr>
<tr>
        <td> Chrome </td>
         <td> YES</td>
         <td>YES </td>
  <td>YES</td>
         </tr>
<tr>
        <td>Firefox </td>
         <td>YES</td>
         <td> YES </td>
  <td>YES</td>
         </tr>
<tr>
        <td>Safari</td>
         <td>YES</td>
         <td>YES</td>
<td> NO</td>
         </tr>
<tr>
        <td> Opera</td>
         <td> YES</td>
         <td> YES </td>
  <td>YES</td>
         </tr>

</table>
</body>
</html>

Output:

Browser MP3 WAV OGG
Internet Explorer YES NO NO
Chrome YES YES YES
Firefox YES YES YES
Safari YES YES No
Opera YES YES YES

Example:

<!DOCTYPE html>
<html>
<body>
<audio controls>
  <source src="horse.ogg" type="audio/ogg">
  <source src="horse.mp3" type="audio/mpeg">
  Your browser does not support the audio element.
</audio>

</body>
</html>

Attributes supported by the <audio> tag

Attribute Value Description
autoplay autoplay Specifies that the audio will start playing as soon as it is ready
controls controls Specifies that audio controls should be displayed
loop loop Specifies that the audio will start over again, every time it is finished
muted muted Specifies that the audio output should be muted
preload auto
metadata
none
Specifies if and how the author thinks the audio should be loaded when the page loads
src URL Specifies the URL of the audio file