The HTML5 <audio>
tag is used to embed audio in a web page.
It's attributes works pretty similar to that of video tag. Not all browsers support all audio formats so, the audio file is encoded using special codecs. It is recommended to use .mp3
file format as it is the most popular audio format globally.
Example to play mp3 file using audio tag in HTML:
The controls
attribute in audio adds controls, like play, pause, and volume.
The <source>
element allows you to specify alternative audio files which the browser may choose from. The browser will use the first recognized format. The text between the <audio>
and </audio>
tags will only be displayed in browsers if the <audio>
element are not support.
Audio File Format | Media Type |
---|---|
.mp3 | audio/mp3 |
.ogg | audio/ogg |
.wav | audio/wav |
Tags | Description |
---|---|
controls |
It defines the audio controls with play/pause buttons. |
autoplay |
It specifies that the audio will start playing as soon as it is ready. |
loop |
It specifies that the audio file will start over again, every time when it is completed. |
muted |
It is used to mute the audio output. |
preload |
It specifies the author view to upload audio file when the page loads. It is ignored if autoplay is used. |
src |
It specifies the address of the audio file. |
.mp3 |
|||||
.ogg |
|||||
.WebM |
Follow Us: