HTML audio tag

HTML <audio> tag embeds the audio or sound in a web page. src attribute defines the address of the audio.

<audio  src="files/sample.mp3" controls>  </audio>

Tag Uses

Specific uses of <article> tag

Tag omission

Both starting and ending tags are necessary for the audio element.

Global Attributes

All the global attributes are applicable on the audio element.

Tag Attributes

Attributes that are applicable to <audio> tag

It specifies the location or address of the audio.

<audio src="address of audio"> </audio>

This attribute plays the audio automatically after loading.

<audio src="address of audio" autoplay> </audio>

This attribute plays the audio automatically from start when it reaches at the end.

<audio src="URL"  loop>  </audio>

The audio is muted by default after the page is loaded.

<audio src="" muted > </audio>

This attribute gives the controls such as play/pause, volume control.

<audio src="" muted > </audio>

It manages the crossorigin requests.

<audio src="" muted > </audio>

represents how much buffering the audio needs before playback.

<audio src="" muted > </audio>

multiple alternative audios

Some browsers don't support all types of media. Multitype audio resources are used so that if one is not supported the other one will be used.

<audio controls>
 <source src="files/sample.mp3" type="audio/mp3" />
 <source src="files/sample.ogg" type="audio/ogg" />
 <p>Sorry, this media type can not be supported in this browser</p>

Here we have embedded two different types of audio.

Note: controls attribute must be used in the <audio> tag otherwise audio will not be played.

Was this article helpful?