HTML Audio Tag

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.

Attributes of HTML Audio Tag

AttributeDescription
controlsIf this attribute is present, the browser will offer controls to allow the user to control audio playback, including volume, seeking, and pause/resume playback.
autoplayA 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.
loopA Boolean attribute: if specified then the audio file will start over again, every time when it is completed.
mutedIt is used to mute the audio output.
preloadIt specifies the author view to upload audio file when the page loads.
srcIt specifies the source URL of the audio file.
Attributes of HTML Audio Tag

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>
HTML Audio Tag Example – Output