HTML <audio> Tag

Beginner
6 min read
Updated: Oct 2026
4 examples
Live preview

Definition and Usage

The <audio> element embeds sound in a document. Point to a file with src or nested <source> elements; the browser picks a format it can play.

Add controls for a native player. Put fallback text (and often a download link) between the tags for browsers that do not support <audio>.

Baseline · Widely available.

Not deprecated. Core support has been stable across browsers since about July 2015. Some attributes (for example loading) still vary.

Autoplay warning.

Unmuted autoplay is often blocked. Prefer user-started playback with controls. If you must autoplay, start muted and make sound opt-in.

Experimental / uneven extras.

loading="lazy" and controlslist are newer or inconsistently supported — treat them as progressive enhancements, not requirements.

HTML Syntax

syntax.html
<audio src=" url" controls>fallback</audio>

Both start and end tags are required. Without controls (or custom UI via JavaScript), the element has no useful visible player for most users.

Attributes

The attributes you will use most often on <audio>:

AttributeDescriptionTry it
srcURL of a single audio file. Optional if you use nested <source> elementsTry it
controlsShows the browser’s default play, pause, seek, and volume UITry it
loopRestarts playback when the track endsTry it
mutedStarts silent. Presence means muted — remove the attribute to unmute by defaultTry it
autoplayStarts as soon as possible. Often blocked unless muted or after user gestureTry it
preloadHint: none, metadata (common default advice), or auto. Browsers may ignore itTry it
crossoriginCORS mode for the media request (anonymous or use-credentials)Try it
controlslistHints which native controls to hide (e.g. nodownload). Support variesSee edge cases

Global Attributes

The <audio> tag also supports the Global Attributes in HTML.

Live Preview

Toggle controls, loop, and muted on a real <audio> element.

A real <audio> using /audio/count.mp3. Toggle chips, then press Apply (or the chip itself).

Player

controls on · loop off · muted off

HTML Examples

Short, copy-ready snippets. Use Try It Yourself for a live editor.

Example 1 — Basic Player with Controls

Embed one file and show the native player UI.

HTML
<figure>
  <figcaption>Sample count audio</figcaption>
  <audio src="/audio/count.mp3" controls>
    Your browser does not support the audio element.
    <a href="/audio/count.mp3">Download MP3</a>.
  </audio>
</figure>
Try It Yourself

How It Works

  1. Set src to the audio URL (here /audio/count.mp3).
  2. Add controls so users can play, pause, seek, and change volume.
  3. Write fallback text inside the tags for browsers without <audio>.
  4. Optional caption with <figure> / <figcaption> labels the clip.

Example 2 — Multiple Formats with <source>

Offer more than one format so the browser can choose what it supports.

HTML
<audio controls>
  <source src="/audio/count.mp3" type="audio/mpeg">
  <source src="/audio/count.ogg" type="audio/ogg">
  <p>
    Download
    <a href="/audio/count.mp3">MP3</a>
    or
    <a href="/audio/count.ogg">OGG</a>.
  </p>
</audio>
Try It Yourself

How It Works

  1. Omit src on <audio> when using nested sources.
  2. List <source> elements with src and a useful type MIME hint.
  3. Browser order: it tries sources top to bottom until one is playable.
  4. Keep a download fallback inside for unsupported clients.

Example 3 — Loop and Preload Hint

Repeat the track and hint how much data to fetch early.

HTML
<audio
  src="/audio/count.mp3"
  controls
  loop
  preload="metadata"
>
  <a href="/audio/count.mp3">Download MP3</a>
</audio>
Try It Yourself

How It Works

  1. loop seeks back to the start when playback ends.
  2. preload="metadata" suggests loading length (and similar) without the full file.
  3. Other hints: none saves bandwidth; auto allows a fuller download.
  4. Remember: preload is only a hint — browsers may ignore it. autoplay overrides preload needs.

Example 4 — Muted Autoplay (When Allowed)

Start silently if the browser permits autoplay; users can unmute via controls.

HTML
<audio
  src="/audio/count.mp3"
  controls
  autoplay
  muted
  loop
>
  <a href="/audio/count.mp3">Download MP3</a>
</audio>
Try It Yourself

How It Works

  1. autoplay asks the browser to start as soon as it can.
  2. muted improves the chance autoplay is allowed (sound starts off).
  3. Keep controls so users can unmute and pause.
  4. Do not rely on unmuted autoplay — many sites block it for a better user experience.

Edge Cases & Pitfalls

Most audio bugs come from autoplay policy, missing controls, or format support.

ux

Always give a way to play and stop

Without controls (or custom UI), users may hear nothing and have no player. Prefer visible controls.

policy

Unmuted autoplay is unreliable

Browsers often require a user gesture. Prefer opt-in play; use muted autoplay only when necessary.

formats

Not every codec works everywhere

Offer multiple <source> formats (commonly MP3 plus OGG or another fallback).

a11y

Transcripts beat missing captions

<audio> does not support WebVTT like <video>. Provide a transcript for speech-heavy clips.

api

muted="false" does not unmute

Boolean attributes: if muted is present, it is muted. Remove the attribute (or use the DOM API) to unmute.

hint

controlslist is only a hint

Values like nodownload may hide UI in some browsers but are not a security boundary — users can still obtain the file URL.

Browser Support

The <audio> element is core HTML media in every modern browser. It is not a Node.js, Deno, or Bun API.

✓ Baseline · Widely available

<audio>

Widely available since about July 2015. Chrome, Firefox, Safari, Edge, and Opera support the element; codec support and autoplay rules still differ by browser and OS.

97% Global support (approx.)
Google Chrome All
Full support
Mozilla Firefox All
Full support
Apple Safari All
Full support
Microsoft Edge All
Full support
Opera All
Full support
Samsung Internet All
Full support
Internet Explorer 9+
Partial
<audio> Widely supported

Bottom line: Safe to use with controls and a format fallback. Treat autoplay, controlslist, and loading="lazy" as progressive extras.

Key Takeaways

  • Role: <audio> embeds sound; controls gives users a real player.
  • Formats: use nested <source> when one codec is not enough.
  • Autoplay: prefer user play; muted autoplay is the safer pattern when needed.
  • Access: fallback links plus a transcript for spoken content.

One line: a good <audio> has a playable source, controls, and a simple fallback.

Default CSS Settings

Without controls, many browsers hide the element. With controls, the player is typically an inline replaced element. A common UA idea looks like this:

default.css
audio {
  display: inline;
}

audio:not([controls]) {
  display: none !important;
  height: 0;
}

You can style the outer player box (width, margin, border). Individual control chrome is browser-specific — use custom UI via the media element API if you need a consistent look.

Frequently Asked Questions

The audio element embeds sound in a page. With the controls attribute, the browser shows a native player for play, pause, seek, and volume — no plugin required.
Use src on audio for one file. Use nested source elements when you offer multiple formats (for example MP3 and OGG); the browser picks the first format it can play.
Most browsers block autoplay with sound until the user interacts with the page. Prefer controls and a clear play action. If you must autoplay, muted autoplay is more likely to be allowed.
Not the same way. audio does not support WebVTT track the way video does. Provide a transcript (and consider video if you need timed captions).
Fallback content for older browsers — for example a short note and a download link. Supporting browsers hide that fallback and show the player instead.
No. muted is a boolean attribute: if it is present, the audio starts muted. Remove the attribute entirely to start unmuted.

Next: b

Mark text for attention without implying stronger importance than strong.

b tutorial →

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.

12 people found this page helpful