👀 Live Preview
A native audio player rendered by the browser:

By the end of this tutorial, you’ll confidently embed sound in web pages with native HTML5 audio controls.
Embed audio with src and controls for a native player.
Use autoplay, loop, muted, and preload.
Offer MP3, Ogg, and AAC fallbacks with <source>.
Respect browser rules for background and muted autoplay.
Add WebVTT tracks with <track> for accessibility.
Ship audio with fallbacks for every major browser.
<audio> Tag?The audio element (<audio>) is an HTML5 embedded content tag for playing sound files. It replaced older plugin-based approaches and works with native browser controls.
Add the controls boolean attribute and the browser renders play, pause, timeline, and volume UI—no Flash or third-party plugins required.
Common uses include podcasts, narration, music clips, sound effects, and language lessons. The element can contain <source> and <track> children.
Point the src attribute at an audio file and add controls so users can play and pause:
<audio src="/audio/count.mp3" controls></audio>controls boolean attribute adds the browser’s default playback UI.<source> elements instead of src for multiple formats.<audio> for unsupported browsers.| Attribute | Values | Purpose |
|---|---|---|
src | URL | Single audio file path or URL |
controls | Boolean | Shows native play/pause/volume UI |
autoplay | Boolean | Start playback on load (often blocked unless muted) |
loop | Boolean | Restart audio when it reaches the end |
muted | Boolean | Silence audio by default; helps autoplay policies |
preload | none | metadata | auto | Hints how much audio to buffer before play |
The <audio> tag supports these key attributes plus global attributes like class and id:
src Required*URL of the audio file. Use <source> instead when offering multiple formats.
src="/audio/count.mp3"controls UIDisplays the browser’s built-in player controls (play, pause, timeline, volume).
<audio controls>autoplay / muted PlaybackStart automatically on load. Browsers often block unmuted autoplay—pair with muted.
autoplay mutedloop / preload Optionalloop replays continuously. preload hints buffering: none, metadata, or auto.
loop preload="auto"<audio src="/audio/count.mp3" controls loop preload="auto"></audio>* Either src on <audio> or at least one nested <source> element is required.
Provide multiple formats using nested <source> elements so every browser finds a playable file:
| Format | MIME Type | Notes |
|---|---|---|
| MP3 | audio/mpeg | Widest support across browsers |
| Ogg Vorbis | audio/ogg | Open format; Firefox-friendly fallback |
| WAV | audio/wav | Uncompressed; large file sizes |
| AAC | audio/mp4 | Common on Safari and mobile devices |
<audio controls>
<source src="/audio/count.mp3" type="audio/mpeg">
<source src="/audio/count.ogg" type="audio/ogg">
Your browser does not support the audio element.
</audio>Four audio patterns with copy-ready code, live previews, and hands-on practice.
A native audio player rendered by the browser:
The simplest form: one file and visible controls.
<audio src="/audio/count.mp3" controls></audio>Combine controls, loop, and preload="auto" for a player that buffers early and repeats when finished.
<audio src="/audio/count.mp3" controls loop preload="auto"></audio>Here are the most frequent ways developers use the <audio> tag.
List MP3 and Ogg sources so the browser picks the first format it supports. Include fallback text for browsers without HTML5 audio.
<audio controls>
<source src="/audio/count.mp3" type="audio/mpeg">
<source src="/audio/count.ogg" type="audio/ogg">
Your browser does not support the audio element.
</audio>Use autoplay and loop for ambient background sound. Add muted because browsers block unmuted autoplay, and always let users pause or mute.
<audio src="/audio/count.mp3" autoplay loop muted></audio>Make audio usable for everyone:
<audio> for unsupported browsers<audio controls src="/audio/count.mp3">
<track kind="captions" src="/audio/count.vtt" srclang="en" label="English">
Your browser does not support the audio element.
</audio>Set src or nest <source> elements inside <audio>.
The browser tests each source until it finds a supported codec, or uses src directly.
With controls, the browser draws play, pause, timeline, and volume without custom JavaScript.
Users listen without leaving the page or installing plugins. Optional <track> adds captions.
The <audio> element is supported in all modern browsers. Internet Explorer 9+ has partial support with some format limitations.
From IE 9 to the latest mobile browsers — embed sound without plugins. Offer multiple formats for legacy partial support.
Bottom line: Ship HTML5 audio with confidence. Provide MP3 plus Ogg or AAC fallbacks and fallback text for the widest reach.
The <audio> tag makes it straightforward to embed sound in web pages with native browser controls. Use controls for user-initiated playback, provide multiple <source> formats for compatibility, and respect autoplay policies.
Pair audio with <track> captions and text transcripts for accessible, engaging multimedia.
controls so users control playback<source> formats (MP3 + Ogg or AAC)<audio><track> for captions on spoken content<audio>Bookmark these before you ship — they’ll make every player accessible and cross-browser ready.
<audio> embeds sound with built-in browser controls—no plugins required.
The controls attribute shows play, pause, timeline, and volume UI.
Use multiple <source> elements so every browser finds a playable codec.
Autoplay usually requires muted or prior user interaction.
<track> adds WebVTT captions for spoken content accessibility.
Supported in all modern browsers; IE 9+ has partial codec support.
Compatibility<audio> element embeds sound content in a web page. With controls, browsers render a built-in player—no plugins needed.audio/mpeg), Ogg (audio/ogg), WAV (audio/wav), and AAC (audio/mp4) are common. Provide several via <source> for broad compatibility.muted for background audio, or let users press play via controls.src on <audio> works for one file. Nested <source> elements let you list multiple formats; the browser uses the first one it can play.Open the Try It editor and experiment with controls, loop, and multiple source formats.
8 people found this page helpful