![]() |
VOOZH | about |
The <audio> tag in HTML5 is used to embed audio content on a webpage. It allows you to play audio files like MP3, OGG, or WAV directly in the browser. The <audio> element provides attributes for controlling playback, such as play, pause, and volume.
<audio>
<source src="sample.mp3" type="audio/mpeg">
</audio>
The various attributes that can be used with the "audio" tag are listed below:
Attributes | Description |
|---|---|
Designates what controls to display with the audio player. | |
Designates that the audio file will play immediately after it loads controls. | |
Designates that the audio file should be muted. | |
Designates the URL of the audio file. | |
Designates that the audio file should continuously repeat. |
The autoplay attribute is used to automatically begin playback of the audio file whenever the URL of the webpage is loaded.
The muted attribute specifies that the audio should be muted on the webpage.
Multiple sources of audios are specified so that if the browser is unable to play the first source, then it will automatically jump to the second source and try to play it.
Adding audios to a webpage using the "embed" tag is an old technique. This method does work, but is comparatively less efficient than the other methods. The user must have a plugin like MIDI or QuickTime because the embed tag requires a plugin for support.
Autoplay is disabled in most Chromium browsers, but muted autoplay is still allowed. Three formats mp3, ogg, and wav are supported by HTML5. The support for each format by different browsers is given below :
| Attribute | 👁 Chrome | 👁 Edge | 👁 Firefox | 👁 Safari | 👁 Opera |
|---|---|---|---|---|---|
| MP3 | ✓ | ✓ | ✓ | ✓ | ✓ |
| WAV | ✓ | ✓ | ✓ | ✓ | ✓ |
| OGG | ✓ | ✓ | ✓ | ✓ | ✗ |