In this article, we will see the <audio> tag in HTML.
- The <audio> tag is used to embed audio files or audio content in the document. like Music or audio streaming.
- The <audio> tag contains one or more <source> tags with different audio sources. The browser will choose wisely the source that it will support.
- The text written between the <audio> and </audio> tags will only be displayed in browsers that do not support the <audio> element.
Example
<audio controls> <source src="horse.ogg" type="audio/ogg"> <source src="horse.mp3" type="audio/mpeg"> Your browser does not support the audio tag. </audio>
There is a number of audio formats but here are three supported audio formats in HTML: MP3, WAV, and OGG.
Browser | MP3 | WAV | OGG |
Edge / IE | YES | YES | YES |
Chrome | YES | YES | YES |
Firefox | YES | YES | YES |
Safari | YES | YES | NO |
Opera | YES | YES | YES |
The browser that supports the <audio> tag is mentioned below,
Browser | Version |
Chrome | 4.0 |
Internet Explorer | 9.0 |
Firefox | 3.5 |
Safari | 4.0 |
Opera | 11.5 |
<audio> tag attributes,
Attribute | Value | Description |
---|---|---|
autoplay | autoplay | Specifies that the audio will start playing as soon as it is ready |
controls | controls | Specifies that audio controls should be displayed (such as a play/pause button etc) |
loop | loop | Specifies that the audio will start over again, every time it is finished |
muted | muted | Specifies that the audio output should be muted |
preload | auto metadata none |
Specifies if and how the author thinks the audio should be loaded when the page loads |
src | URL | Specifies the URL of the audio file |
So let’s start coding within the next blog. If you’ve got any questions regarding this blog, please let me know in the comments.