audio

The audio element embeds sound content with native playback controls, styled variants, and an optional track listing for playlists.

Description

The <audio> element embeds audio content with native browser playback controls. Vanilla Breeze styles audio players to be block-level and full-width by default, with variants for compact and minimal layouts.

Audio handling follows a progressive enhancement approach with four layers — each functional on its own:

  1. Layer 1 — Native <audio> with <source> fallback chain
  2. Layer 2 — CSS styling: accent-color, border-radius, color-scheme
  3. Layer 3 — Track listing via <details> + <ol class="track-list">
  4. Layer 4<audio-player> web component with custom controls

When to Use

  • Podcasts — Episode players with playback controls
  • Music players — Song or album playback
  • Sound effects — UI feedback or game audio
  • Voice recordings — Interviews, voicemail, audio messages
  • Audiobooks — Narrated content

Layer 1: Native Baseline

Works everywhere with no CSS or JS. Always include at least one <source> with a type attribute and a download link as the ultimate fallback.

Multi-Source Format Chain

List formats best-to-worst — the browser picks the first it supports.

Layer 2: Styled Variants

CSS-only improvements via VB tokens. The native player gains visual polish without any new HTML.

The demo above shows all three variants: default (full-width), compact, and minimal.

Default

Full-width player with accent-color, border-radius, and color-scheme from VB tokens.

.compact

Max-width constrained (320px) for inline usage or sidebars.

.minimal

Reduced height for tight layouts.

Layer 3: Track Listing

HTML + CSS only. <details>/<summary> exposes a track list that shows and hides natively. Without JS, track links navigate to the audio file. With the playlist utility loaded, clicking a track updates the audio source and plays it.

Interactive Playlist (with JS)

Wrap the audio and track list in a container with class .audio-standalone to enable click-to-play behavior via the playlist utility.

Track List Data Attributes

AttributeSet byMeaning
data-audio-activeComponent + authorCurrently loaded/playing track
data-audio-playedComponentTrack has been played this session
data-audio-favoriteAuthorEditorially marked as a highlight

Text Tracks

Captions

Chapters

Audio Attributes

Attribute Description
controls Show native playback controls (required for user interaction)
autoplay Start playing automatically (discouraged — poor UX)
muted Start with audio muted
loop Restart audio when it ends
preload none, metadata, or auto

Preload Options

Audio Formats

FormatMIME TypeSupport
MP3audio/mpegUniversal — best for compatibility
AACaudio/aacGood quality, wide support
Ogg Vorbisaudio/oggOpen format, Firefox/Chrome
Opusaudio/opusBest quality/size ratio, modern browsers
WAVaudio/wavUncompressed, large files
FLACaudio/flacLossless, growing support

Accessibility

Transcripts

Provide text transcripts for audio content so deaf users and those who cannot play audio can access the information.

Best Practices

  • Always provide a text transcript for important audio
  • Never autoplay audio — it is disruptive and inaccessible
  • Ensure controls are visible and keyboard accessible
  • Provide context about what the audio contains
  • Include duration information when available

CSS Reference

Styles defined in /src/native-elements/audio/styles.css

SelectorProperties
audio display: block; width: 100%; border-radius: var(--radius-m); accent-color: var(--color-primary); color-scheme: light dark;
audio.compact max-width: 320px;
audio.minimal height: 2.5rem;
details:has(.track-list) border: 1px solid var(--color-border); border-radius: var(--radius-m);
.track-list li[data-audio-active] background: color-mix(in oklch, var(--color-primary), transparent 85%);

Related

  • <audio-player> — Platform web component with custom controls (Layer 4)
  • <audio-visualizer> — Canvas visualization companion
  • <video> — Video content with similar API
  • <source> — Define multiple audio sources for format fallback
  • <track> — Synchronized text tracks (captions, chapters)