HTML audio Tag

HTML audio Tag is used to play audio files like music or audio podcasts.

Syntax of HTML audio Tag

HTML audio Tag is HTML5 tag. The syntax of HTML audio Tag is shown below. It has both ending and starting tags.

<!DOCTYPE html>
<html>
<head>
</head>
<body>
<audio>
</audio>
</body>
</html>

Usage of HTML audio Tag

The audio tag is used to play sounds, like songs, podcasts or any other type of audio streams. With HTML audio Tag you can embed audio file on your website. Look at the example below.

Example of HTML audio Tag

Simple example of HTML audio tag is shown below.

<!DOCTYPE html>
<html>
<head>
</head>
<body>
<audio controls>
<source src="song.mp3" type="audio/mpeg">
Your browser does not support audio tag.
</audio>
</body>
</html>

In the above example an audio file named song.mp3 is embedded using audio tag. The text that you see written between two starting and ending audio tags will display if the browser doesn't support the audio tag or any format of audio file.

Supported Formats for the HTML audio Tag

The HTML audio Tag only supports three main formats of audio files. These formats are given below.

  • Mp3
  • WAV
  • OGG

Browser Support for HTML audio Tag

All Major browsers support HTML audio Tag, however Internet Explorer 8.0 or earlier versions don't support it.

Also Internet Explorer only supports Mp3 format of audio file, while Wav and OGG are not supported.

Supported MIME types for Audio Formats

All three supported audio formats for HTML audio Tag have different MIME type values.

  • Mp3 -> audio/mpeg
  • Wav -> audio/wav
  • OGG -> audio/ogg

Attributes of HTML audio Tag

Following attributes are used inside HTML audio Tag.

  • muted attribute

    It makes the audio file silent, the sound will be muted.

  • preload attribute

    It defines how the audio file should load when the page is loaded.

  • src attribute

    It defines the url of the audio file.

  • loop attribute

    It defines that audio file will repeat every time after it's finished.

  • controls attribute

    It allows the browser to display the control buttons (like play and pause etc) for the audio file.

  • autoplay attribute

    It specifies that the audio should automatically play after the page is loaded.

Global Attributes Support in HTML audio Tag

HTML audio Tag supports all Global HTML Attributes.

Event Attributes Support in HTML audio Tag

HTML audio tag supports all Event Attributes.

HTML audio Tag Video

Watch our video on HTML audio Tag and subscribe our Youtube Channel.

HTML anchor Tag HTML abbr Tag HTML acronym Tag HTML address Tag HTML applet Tag HTML area Tag HTML article Tag HTML aside Tag HTML audio Tag HTML b Tag HTML base Tag HTML basefont Tag HTML bdi Tag HTML bdo Tag HTML big Tag HTML blockquote Tag HTML body Tag HTML br Tag HTML Button Tag HTML Canvas Tag HTML Caption Tag HTML Center Tag HTML Cite Tag HTML Code Tag HTML Col Tag HTML colgroup Tag HTML comment Tag HTML data Tag HTML datalist Tag HTML dd Tag HTML del Tag HTML details Tag HTML dfn Tag HTML dialog Tag HTML dir Tag HTML div Tag HTML dl Tag HTML Doctype Tag HTML dt Tag HTML em Tag HTML embed Tag HTML fieldset Tag HTML figcaption Tag HTML figure Tag HTML font Tag HTML footer Tag HTML form Tag HTML frame Tag HTML frameset Tag HTML Heading Tags HTML head Tag HTML header Tag HTML hr Tag HTML html Tag HTML i Tag HTML iframe Tag HTML img Tag HTML input Tag HTML ins Tag HTML kbd Tag HTML label Tag HTML legend Tag HTML li Tag HTML link Tag HTML main Tag HTML map Tag HTML mark Tag HTML meta Tag HTML meter Tag HTML nav Tag HTML noframes Tag HTML noscript Tag HTML object Tag HTML ol Tag HTML optgroup Tag HTML option Tag HTML output Tag HTML p Tag HTML param Tag HTML picture Tag HTML pre Tag HTML progress Tag HTML q Tag HTML rp Tag HTML rt Tag HTML ruby Tag HTML s Tag