Vanilla Breeze v0.7.4

Vanilla Breeze v0.7.4 released

0.7.4 gives the Ambient pack weather. A page names one feed URL on its own site, and the pack sets data-weather from it, uses its sunrise and sunset for dawn and dusk, and never shows a stale observation. Helpers for producing the feed from Open-Meteo are included. Ambient p…

Read the release notes

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

The track list itself is HTML + CSS: <details>/<summary> shows and hides it natively, and on its own each track link simply navigates to the audio file. The demo below is wrapped in a data-audio-playlist container, which turns on the playlist utility (JavaScript) — clicking a track there swaps the audio source and plays it in place. See Interactive Playlist for that wrapper; the code sample directly below is the bare, script-free structure.

Interactive Playlist (with JS)

Wrap the audio and track list in a container with the data-audio-playlist attribute to enable click-to-play behavior via the playlist utility (src/utils/audio-playlist-init.js). If the script does not run, the links fall back to navigating to each file.

The data-audio-playlist contract

  • Attribute — data-audio-playlist is a boolean attribute on any container element (a <section>, <article> or <figure>); it takes no value.
  • Structure — the container holds one <audio> and one .track-list (usually inside <details>). Each track is an <li> with an <a href> pointing at its audio file. Containers without both are left alone.
  • Click — clicking a track link sets the audio source to the link's URL, moves data-audio-active to that <li> and starts playback. A refused play() (autoplay policy, unloadable file) is caught, never thrown.
  • Ended — the finished track gets data-audio-played and keeps data-audio-active; the next track in list order then starts. After the last track playback stops and that track stays active. A native <audio loop> repeats the current track instead (it never ends).
  • Once only — an enhanced container is marked data-audio-playlist-init. Containers added to the page later are enhanced automatically.
  • Not inside <audio-player> — the component runs its own playlist with the same click and ended behavior (it shares the track-activation code), and adds shuffle and list looping.

Track List Data Attributes

AttributeSet byMeaning
data-audio-activeScript + authorCurrently loaded track (stays on a track after it ends)
data-audio-playedScriptTrack has played to the end this session
data-audio-favoriteAuthorEditorially marked as a highlight

Text Tracks

Captions

<audio> accepts <track> children, but browsers do not render text tracks for audio — there is no video surface to draw cues on, so a kind="captions" track is parsed and then never shown. The cues are still available through the textTracks API, so displaying them requires a custom renderer that listens for cuechange and writes the active cue into the page.

For most content, prefer one of these instead:

  • A full text transcript next to the player (the most robust option, and what WCAG asks for prerecorded audio)
  • A <video> element, which does render caption tracks natively, if synchronised on-screen captions are required

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%);
.track-list li[data-audio-played]:not([data-audio-active]) opacity: 0.6; (the loaded track keeps full emphasis)

Related

↑