The <audio>, <source> & <track> elements
The <audio> tag embeds sound, such as music, a podcast or a sound effect, in a web page. Add the controls attribute to show a play button, timeline and volume. List several <source> elements to offer different file formats, and the browser plays the first one it supports. Without controls, the player is invisible.
Last updated: October 3, 2026
Quick facts
| Category | Flow content, phrasing content, embedded content (interactive and palpable when it has controls) |
| Content model | Optional <source> elements (if there is no src), then <track> elements, then fallback content |
| Tag omission | <audio>: neither tag can be omitted. <source> and <track> are void elements |
| Permitted parents | Any element that accepts embedded content |
| DOM interfaces | HTMLAudioElement, HTMLSourceElement, HTMLTrackElement |
Syntax
Live example
Edit the code below and watch the preview update instantly.
Attributes
<audio>
| Attribute | Description |
|---|---|
| src | The URL of the sound file (or use <source> children instead) |
| controls | Shows the browser’s play, pause, timeline and volume controls |
| autoplay | Starts playing as soon as possible. Most browsers block this unless the audio is also muted |
| loop | Starts again from the beginning when it ends |
| muted | Starts with the sound off |
| preload | none, metadata (just length and details) or auto (the whole file) |
<source>
| Attribute | Description |
|---|---|
| src | The URL of this version of the file |
| type | The file’s format, e.g. audio/mpeg or audio/ogg, so the browser can skip formats it can’t play |
<track>
| Attribute | Description |
|---|---|
| kind | subtitles, captions, descriptions, chapters or metadata |
| src / srclang / label | The WebVTT file, its language and the name shown to users |
| default | Turns this track on by default |
Common examples
A podcast episode with a download link
Offer a plain download link inside the element as a fallback, and below the player for people who want to listen later.
Play a sound when a button is clicked
For short sound effects you don’t even need the element in your HTML — create an Audio object in JavaScript.
Your own play/pause button
Leave out controls and control the player from a button that shows its state.
<audio> vs Spotify and SoundCloud embeds
With <audio> you host the file yourself: no third-party branding or tracking, full control over the player, and the file is always available. The cost is storage and bandwidth, and you have to prepare the files (compression, formats) yourself.
Embedding a player from Spotify, SoundCloud or a podcast host uses an <iframe> and hands all of that to the platform, plus listeners can follow or subscribe there. For sound effects and short clips, use <audio>; for music and podcasts you want discovered, an embed is usually easier.
| <audio> | Platform embed | |
|---|---|---|
| Hosting | Yours | The platform’s |
| Player control | Full | Limited |
| Best for | Sound effects, short clips | Music, podcasts |
Common mistakes to avoid
- Playing sound automatically. Browsers block it, and visitors find it jarring. Let people press play.
- No controls and no custom buttons. Without
controls(or your own buttons), there’s no way to pause or stop the sound. - Huge WAV files. Uncompressed audio is many times larger than MP3 or AAC; convert it before uploading.
- No transcript. Deaf and hard-of-hearing visitors, and search engines, can’t access spoken content without one.
Accessibility & SEO tips
- Publish a text transcript for podcasts and spoken audio — it helps accessibility and gives search engines words to index.
- Use
preload="metadata"so the page loads only the length and details until someone presses play. - Make custom controls real buttons with clear labels so they work with the keyboard and screen readers.
Browser support
Supported in all modern browsers. MP3 plays everywhere; AAC (.m4a) and Ogg are also widely supported, so MP3 alone covers almost every visitor.
Tutorial: How to embed a YouTube video