HTML <audio> Tag

Beginner
⏱️ 7 min read
📚 Updated: Jun 2026
🎯 4 Examples
HTML5 Media

What You’ll Learn

By the end of this tutorial, you’ll confidently embed sound in web pages with native HTML5 audio controls.

01

Basic Playback

Embed audio with src and controls for a native player.

02

Key Attributes

Use autoplay, loop, muted, and preload.

03

Multiple Formats

Offer MP3, Ogg, and AAC fallbacks with <source>.

04

Autoplay Policies

Respect browser rules for background and muted autoplay.

05

Captions

Add WebVTT tracks with <track> for accessibility.

06

Browser Support

Ship audio with fallbacks for every major browser.

What Is the <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.

💡
Native browser player

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.

📝 Syntax

Point the src attribute at an audio file and add controls so users can play and pause:

audio.html
<audio src="/audio/count.mp3" controls></audio>
  • The controls boolean attribute adds the browser’s default playback UI.
  • Use nested <source> elements instead of src for multiple formats.
  • Include fallback text inside <audio> for unsupported browsers.

⚡ Quick Reference

AttributeValuesPurpose
srcURLSingle audio file path or URL
controlsBooleanShows native play/pause/volume UI
autoplayBooleanStart playback on load (often blocked unless muted)
loopBooleanRestart audio when it reaches the end
mutedBooleanSilence audio by default; helps autoplay policies
preloadnone | metadata | autoHints how much audio to buffer before play

🧰 Attributes

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 UI

Displays the browser’s built-in player controls (play, pause, timeline, volume).

<audio controls>
autoplay / muted Playback

Start automatically on load. Browsers often block unmuted autoplay—pair with muted.

autoplay muted
loop / preload Optional

loop replays continuously. preload hints buffering: none, metadata, or auto.

loop preload="auto"
attributes.html
<audio src="/audio/count.mp3" controls loop preload="auto"></audio>

* Either src on <audio> or at least one nested <source> element is required.

🎶 Supported Audio Formats

Provide multiple formats using nested <source> elements so every browser finds a playable file:

FormatMIME TypeNotes
MP3audio/mpegWidest support across browsers
Ogg Vorbisaudio/oggOpen format; Firefox-friendly fallback
WAVaudio/wavUncompressed; large file sizes
AACaudio/mp4Common on Safari and mobile devices
formats.html
<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>

Examples Gallery

Four audio patterns with copy-ready code, live previews, and hands-on practice.

👀 Live Preview

A native audio player rendered by the browser:

Basic Audio Player

The simplest form: one file and visible controls.

basic-audio.html
<audio src="/audio/count.mp3" controls></audio>
Try It Yourself

Controls, Loop & Preload

Combine controls, loop, and preload="auto" for a player that buffers early and repeats when finished.

loop-preload.html
<audio src="/audio/count.mp3" controls loop preload="auto"></audio>
Try It Yourself

📚 Common Use Cases

Here are the most frequent ways developers use the <audio> tag.

Multiple Source Formats

List MP3 and Ogg sources so the browser picks the first format it supports. Include fallback text for browsers without HTML5 audio.

multiple-formats.html
<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>
Try It Yourself

Autoplay & Background Audio

Use autoplay and loop for ambient background sound. Add muted because browsers block unmuted autoplay, and always let users pause or mute.

background-music.html
<audio src="/audio/count.mp3" autoplay loop muted></audio>
Try It Yourself

♿ Accessibility

Make audio usable for everyone:

  • controls — always provide a way to play, pause, and adjust volume
  • Fallback text — place readable text inside <audio> for unsupported browsers
  • <track> — add captions or subtitles with WebVTT files for spoken content
  • Autoplay — avoid surprising users; respect reduced-motion and focus preferences
  • Transcripts — offer a text alternative alongside long-form audio
captions.html
<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>

🧠 How <audio> Works

1

Author adds audio markup

Set src or nest <source> elements inside <audio>.

Markup
2

Browser picks a playable format

The browser tests each source until it finds a supported codec, or uses src directly.

Compatibility
3

Native controls render

With controls, the browser draws play, pause, timeline, and volume without custom JavaScript.

UI
=

Sound plays in the page

Users listen without leaving the page or installing plugins. Optional <track> adds captions.

Universal Browser Support

The <audio> element is supported in all modern browsers. Internet Explorer 9+ has partial support with some format limitations.

Baseline · Since HTML5

Native audio everywhere users listen

From IE 9 to the latest mobile browsers — embed sound without plugins. Offer multiple formats for legacy partial support.

98% Modern browser support
Google Chrome All versions · Desktop & Mobile
Full support
Mozilla Firefox All versions · Desktop & Mobile
Full support
Apple Safari All versions · macOS & iOS
Full support
Microsoft Edge All versions · Chromium & Legacy
Full support
Internet Explorer IE 9+ · Limited codec support
Partial support
Opera All modern versions
Full support
<audio> tag 98% supported

Bottom line: Ship HTML5 audio with confidence. Provide MP3 plus Ogg or AAC fallbacks and fallback text for the widest reach.

Conclusion

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.

💡 Best Practices

✅ Do

  • Add controls so users control playback
  • Offer multiple <source> formats (MP3 + Ogg or AAC)
  • Include fallback text inside <audio>
  • Compress audio files for faster page loads
  • Use <track> for captions on spoken content

❌ Don’t

  • Autoplay loud audio without user consent
  • Rely on a single obscure audio format
  • Hide controls when users need to pause or mute
  • Use huge uncompressed WAV files for web delivery
  • Forget transcripts for long narration or podcasts

Key Takeaways

Knowledge Unlocked

Six truths every developer should know about <audio>

Bookmark these before you ship — they’ll make every player accessible and cross-browser ready.

6
Core concepts
▶️ 02

Controls UI

The controls attribute shows play, pause, timeline, and volume UI.

Reference
💾 03

Format Fallbacks

Use multiple <source> elements so every browser finds a playable codec.

Compatibility
🔊 04

Autoplay Rules

Autoplay usually requires muted or prior user interaction.

Policy
05

Captions

<track> adds WebVTT captions for spoken content accessibility.

A11y
🌐 06

Universal Support

Supported in all modern browsers; IE 9+ has partial codec support.

Compatibility

❓ Frequently Asked Questions

The <audio> element embeds sound content in a web page. With controls, browsers render a built-in player—no plugins needed.
MP3 (audio/mpeg), Ogg (audio/ogg), WAV (audio/wav), and AAC (audio/mp4) are common. Provide several via <source> for broad compatibility.
Browsers block autoplay with sound to protect users. Use 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.
Yes in all modern browsers. IE 9+ has partial support. Always include fallback text inside the element.

Build an Audio Player

Open the Try It editor and experiment with controls, loop, and multiple source formats.

Try Audio Player →

About the author

Mari Selvan M P
Mari Selvan M P 🔗

Developer, cloud engineer, and technical writer

  • Experience 12 years building web and cloud systems
  • Focus Full Stack Development, AWS, and Developer Education

I write practical tutorials so students and working developers can learn by doing—from databases and APIs to deployment on AWS.

8 people found this page helpful