HTML audio tag is used to define sounds such as music and other audio clips. It is used to embed sound content in documents.
Supported file format for HTML 5 audio tag are: mp3, wav and ogg.
The <audio>
tag contains one or more <source>
tags with different audio sources. The browser will choose the first source it supports.
Contents
hide
Attributes of HTML Audio Tag
Attribute | Description |
---|---|
controls | If this attribute is present, the browser will offer controls to allow the user to control audio playback, including volume, seeking, and pause/resume playback. |
autoplay | A Boolean attribute: if specified, the audio will automatically begin playback as soon as it can do so, without waiting for the entire audio file to finish downloading. |
loop | A Boolean attribute: if specified then 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. |
src | It specifies the source URL of the audio file. |
The text between the <audio>
and </audio>
tags will only be displayed in browsers that do not support the <audio>
element.
Example
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>HTML Audio Tag Example</title>
</head>
<body>
<audio controls loop>
<source src="https://eywiah.com/wp-content/uploads/2021/12/koyal.mp3" type="audio/mpeg">
</audio>
<br>
<!-- OR -->
<audio controls loop src="https://eywiah.com/wp-content/uploads/2021/12/koyal.mp3"></audio>
</body>
</html>