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…
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:
Layer 1 — Native <audio> with <source> fallback chain
Works everywhere with no CSS or JS. Always include at least one <source> with a typeattribute and a download link as the ultimate fallback.
Basic audio with fallback download link
<audiocontrols><sourcesrc="track.ogg"type="audio/ogg"><sourcesrc="track.mp3"type="audio/mpeg"><p> Your browser does not support audio playback.<ahref="track.mp3"download>Download the audio file</a>.</p></audio>
Multi-Source Format Chain
List formats best-to-worst — the browser picks the first it supports.
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.
Wrap the audio and track list in a container with the data-audio-playlistattribute 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.
Standalone interactive playlist
<sectiondata-audio-playlist><audiocontrols><sourcesrc="tracks/01-opening.mp3"type="audio/mpeg"><p><ahref="tracks/01-opening.mp3"download>Download track 1</a></p></audio><details><summary>Track Listing</summary><olclass="track-list"><lidata-audio-active><ahref="tracks/01-opening.mp3">01. Opening</a><spanclass="track-meta"><timedatetime="PT2M14S">2:14</time></span></li><li><ahref="tracks/02-main.mp3">02. Main Theme</a><spanclass="track-meta"><timedatetime="PT3M45S">3:45</time></span></li></ol></details></section>
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.
Currently loaded track (stays on a track after it ends)
data-audio-played
Script
Track has played to the end this session
data-audio-favorite
Author
Editorially 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
Captions track on audio (needs a custom renderer)
<audiocontrols><sourcesrc="podcast.mp3"type="audio/mpeg"><!-- Parsed but not displayed by the browser --><trackkind="captions"src="captions.vtt"srclang="en"label="English"default><p><ahref="podcast.mp3"download>Download podcast</a></p></audio><paria-live="polite"class="caption-output"></p><script>const audio = document.querySelector('audio');const out = document.querySelector('.caption-output');const track = audio.textTracks[0]; track.mode = 'hidden'; // load cues without the UA trying to render them track.addEventListener('cuechange', () => { out.textContent = track.activeCues[0]?.text ?? ''; });</script>
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 preload attribute options
<!-- Don't preload - best for long content or many players --><audiocontrolspreload="none">...</audio><!-- Preload metadata only - duration, dimensions --><audiocontrolspreload="metadata">...</audio><!-- Preload entire file - small files, likely to play --><audiocontrolspreload="auto">...</audio>
Audio Formats
Format
MIME Type
Support
MP3
audio/mpeg
Universal — best for compatibility
AAC
audio/aac
Good quality, wide support
Ogg Vorbis
audio/ogg
Open format, Firefox/Chrome
Opus
audio/opus
Best quality/size ratio, modern browsers
WAV
audio/wav
Uncompressed, large files
FLAC
audio/flac
Lossless, growing support
Accessibility
Transcripts
Provide text transcripts for audio content so deaf users and those who cannot play audio can access the information.
Audio with transcript link for accessibility
<figure><audiocontrols><sourcesrc="interview.mp3"type="audio/mpeg"></audio><figcaption> Interview with Dr. Smith about climate change.<ahref="transcript.html">Read the transcript</a></figcaption></figure>
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