HTML Tags
HTML5 <audio> Tag
The <audio> tag embeds sound content, such as music or podcasts, with optional built-in playback controls.
What is the <audio> tag?
The <audio> element, introduced in HTML5, plays audio natively in the browser without a plug-in. You can point it at a file with the src attribute or provide multiple <source> children so the browser can pick a format it supports. Text inside the element is fallback content for very old browsers.
Complete example
<!DOCTYPE html>
<html lang="en">
<body>
<audio controls>
<source src="song.ogg" type="audio/ogg" />
<source src="song.mp3" type="audio/mpeg" />
Your browser does not support the audio element.
</audio>
</body>
</html>Attributes
| Attribute | Description |
|---|---|
| src | URL of the audio file (alternative to using <source> children). |
| controls | Shows the browser's built-in play, pause, and volume controls. |
| autoplay | Starts playing as soon as it can (often blocked unless muted). |
| loop | Restarts the audio from the beginning when it ends. |
| muted | Starts the audio muted. |
| preload | Hints how much to preload: none, metadata, or auto. |
Most browsers block autoplay of audio with sound. If you need autoplay, the audio usually must be muted. Always provide controls for accessibility.
The <audio> tag is supported in all modern browsers. Provide MP3 plus at least one open format such as OGG for the broadest compatibility.
