HTML Audio

Audio tag in HTML

Before HTML-5 there is no standard to way for play audio files on the web page.

HTML-5 <audio> tag introduce a standard way for embedding audio on the web page.

There are two ways to specify a source of an audio file with the <audio> tag.

<audio src="audio.mp3" controls>
  Audio element not supported by your browser.

The text between the <audio> tag will be displayed if your browser doesn't support <audio> tag.

Another way to specify source with the <audio> tag is to use <source> elements inside the audio tag which specifies multiple source files of different file formats.

<audio src="audio.mp3" controls>
  <source src="audio.mp3" type="media/mp3">
  <source src="audio.ogg" type="media/ogg">

In the above code snippet, if the browser doesn't support the first file format then try the next one. In this way, the browser chooses the first recognized format.

HTML <audio> tag - Supported file format

File FormatMedia Type