HTML <audio> Tag
In this tutorial, we will learn about audio tag in HTML with the help of examples.
<audio> Tag
Audio tag <audio> is used to play an audio file on the web page.
The <source> tag allows us to specify alternative audio files.
Control attribute is used to adds audio controls, like play, pause, volume.
The text inside <audio> and </audio> element will display when the browser doesn’t support the <audio> element.
Common audio formats are MP3, MP4 (It is video format but also be used for audio).
Syntax
<audio>....</audio>
Example
<!DOCTYPE html>
<html>
<head>
<title>Audio Tag</title>
</head>
<body>
<audio controls>
<source src = "audio.mp3" type = "audio/mp3">
<source src = "audio.ogg" type = "audio/ogg">
Your browser does not support the audio format.
</audio>
</body>
</html>
Output
Specific Attribute
Attribute | Value | Description |
---|---|---|
autoplay | autoplay | Automatically starts playing audio as it is ready to play |
controls | controls | Used to display basic audio controls |
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 the audio should be loaded when the page will load or not |
src | URL | Specifies the URL or source of the audio file |
Global Attribute
Audio Tag support all the global attributes of HTML.
Event Attribute
Audio Tag support all the event attributes of HTML.
Next Tutorial
We hope that this tutorial helped you develop better understanding of the concept of Audio tag in HTML.
Keep Learning : )
In the next tutorial, you'll learn about HTML b
Tag.