Vanilla Breeze

audio-visualizer

Canvas-based audio visualization that pairs with any <audio> element via the for attribute. Supports bars, waveform, and circle modes.

Overview

A companion component that draws canvas-based audio visualizations. It connects to any <audio> element by ID via the for attribute — mirroring the <label for=""> pattern.

Separated from <audio-player> so it can be independently positioned, omitted, or paired with a plain <audio> element.

Visualization Modes

Bars (default)

Classic frequency bar chart equalizer. Press play to see the visualization.

Waveform

Time-domain oscilloscope line.

Circle

Radial frequency display.

Paired with audio-player

The visualizer works alongside <audio-player> — just give the inner <audio> an ID.

Attributes

AttributeRequiredDefaultDescription
forYes--ID of the target <audio> element
data-modeNobarsVisualization style: bars, waveform, circle
data-fft-sizeNo256AnalyserNode FFT size (power of 2, 32-32768)

CSS Custom Properties

PropertyDefaultDescription
--audio-visualizer-colorvar(--color-primary)Bar / waveform draw color
--audio-visualizer-bgvar(--color-surface-sunken)Canvas background
--audio-visualizer-height80pxCanvas block size
--audio-visualizer-radiusvar(--radius-m)Canvas border radius

Behavior

  • Lazy AudioContext — created on first play event, respects browser autoplay policy
  • Shared AudioContext — multiple visualizers on one page share a single context (browsers cap at ~6)
  • Off-screen pause — stops canvas rendering via IntersectionObserver when not visible
  • Reduced motion — stops canvas animation when prefers-reduced-motion: reduce is set; audio continues playing
  • Graceful fallback — if AudioContext is unavailable, renders nothing and throws no errors

Progressive Enhancement

Without JS, the visualizer renders nothing — the <audio> plays normally. The visualizer is pure enhancement with no impact on audio functionality.

The :not(:defined) CSS rule hides the element before JS loads, preventing a flash of unstyled content.

Accessibility

  • Canvas is aria-hidden="true" — purely decorative
  • Respects prefers-reduced-motion
  • Does not interfere with audio element controls or keyboard navigation

Related