Example

A simple <audio> tag:

Laboratory

description & Usage

The <audio> tag is used to add music or any audio media to an HTML document.

The <audio> tag contains one or more <source> tags to specify the URLs of the audio sources.

We can use one or more <source> with different file extensions. The browser will automatically play the first audio file that it supports.

Two important Attributes of this tag include:

  1. autoplay attribute: specifies the automatic playback of the video.
  2. controls attribute: displays the control buttons of the sound file.

The supported audio formats by the browser include: MP3, WAV, OGG.

format edge chrome firefox safari opera
MP3 have have have have have
WAV prescription 79 have have have have
OGG prescription 79 have have dont have have

 

Take a look at the <audio> tag page.

Notes

Note: You can also introduce the audio file to the <audio> tag using the src attribute without using the <source> tag.

<audio src="/audio.mp3"></audio>

Note: If the browser does not support the <audio> tag, the text within the <audio> tag is displayed.

<audio src="/audio.mp3">Your browser not support audio</audio>

Note: The audio file can also be displayed using the <embed> tag, but it is recommended to use the <audio> tag.

Browser compatibility and Support

# Chrome Edge Firefox Safari Opera
<audio>

Global Attributes

The <audio> tag supports the HTML Global Attributes.

Event Attributes

The <audio> tag supports the HTML Event Attributes.