Audio Waveform Tone Visualizer — Free HTML CSS JS Snippet

Audio Waveform Tone Visualizer · Charts · Plain HTML, CSS & JS · Live preview

What's included

Features

Real Web Audio API sine oscillator with no external audio files
Live oscilloscope waveform drawn on canvas via AnalyserNode.getByteTimeDomainData()
requestAnimationFrame render loop synced to the actual audio signal
Live frequency slider that updates oscillator.frequency.value while playing
GainNode used to keep volume at a safe, comfortable listening level
Full teardown on Stop: cancels the animation frame and closes the AudioContext
Idle flat-line state shown before any interaction
Zero dependencies, pure Web Audio and Canvas 2D APIs

About this UI Snippet

Audio Waveform Tone Visualizer — Live Oscilloscope With Web Audio API

Screenshot of the Audio Waveform Tone Visualizer snippet rendered live

This snippet builds a real-time oscilloscope out of nothing but the browser's Web Audio API and a canvas element — no audio files, no libraries. Pressing Play Tone starts an AudioContext, generates a sine wave with an OscillatorNode, and routes it through an AnalyserNode so the raw waveform samples can be drawn to the screen as they happen.

The audio graph

Three nodes are wired together: the OscillatorNode generates the tone, a GainNode sets its volume, and an AnalyserNode taps the signal before it reaches the speakers via audioCtx.destination. The AnalyserNode doesn't change the sound at all — it's a read-only observation point that exposes analyser.getByteTimeDomainData(), the raw amplitude samples used to draw the waveform.

Drawing the waveform

A requestAnimationFrame loop repeatedly calls getByteTimeDomainData() into a Uint8Array, then walks the array plotting each sample as a point on the canvas, connected into a continuous line. Because the loop runs on every animation frame while the oscillator keeps generating a fresh signal, the line appears to move and breathe in real time — a true oscilloscope trace of the actual audio being generated, not a decorative animation.

Live frequency control

Dragging the frequency slider sets oscillator.frequency.value directly while the tone is playing — the Web Audio API allows this property to be changed on a live, connected oscillator node, so the pitch and the waveform's visual period both shift immediately without needing to restart the AudioContext.

Clean teardown

Stop cancels the animation frame, stops and disconnects the oscillator, disconnects the gain and analyser nodes, and closes the AudioContext entirely, so no audio processing or animation keeps running in the background after the user is done.

Build with AI

Build, Understand, Optimize, and Extend It With AI

Hand this snippet's HTML, CSS, and JavaScript to an AI coding assistant like Claude and ask it to adapt "Audio Waveform Tone Visualizer" to your project — restyle it to match your design system, wire it up to real data instead of the static example, or port it to the framework you're building in.

Prompt to recreate it

Copy this into your AI assistant of choice to build the effect from scratch, or as a jumping-off point for your own variant:

text
Build a charts component called "Audio Waveform Tone Visualizer" using plain HTML, CSS, and vanilla JavaScript — no framework, no build step.

Requirements:
- Match the structure and behavior of the "Audio Waveform Tone Visualizer" snippet from the UI Snippets Library.
- Keep the markup semantic and the styling self-contained (no external dependencies beyond what the original snippet uses).
- Keep the JavaScript vanilla, with no framework runtime required.
- Make it easy to restyle via CSS custom properties or class overrides so it can be dropped into a real project.

Want to tighten it up first? Run this prompt through the AI Prompt Studio to score it across 8 quality dimensions, catch anti-patterns, and tune the wording for Claude, ChatGPT, or Gemini before you paste it in.

Source Code

<div class="wv-card">
  <div class="wv-head">
    <div>
      <span class="wv-eyebrow">Oscilloscope</span>
      <h2>Tone Visualizer</h2>
    </div>
    <span class="wv-status" id="wvStatus">Idle</span>
  </div>

  <canvas class="wv-canvas" id="wvCanvas" width="600" height="200"></canvas>

  <div class="wv-controls">
    <button class="wv-btn wv-btn-play" id="wvPlayBtn">
      <svg width="14" height="14" viewBox="0 0 24 24" fill="currentColor"><path d="M8 5v14l11-7z"/></svg>
      Play Tone
    </button>
    <button class="wv-btn wv-btn-stop" id="wvStopBtn" disabled>
      <svg width="14" height="14" viewBox="0 0 24 24" fill="currentColor"><path d="M6 6h12v12H6z"/></svg>
      Stop
    </button>
  </div>

  <div class="wv-slider-row">
    <label for="wvFreq">Frequency</label>
    <input type="range" id="wvFreq" min="80" max="1200" value="220" step="1" />
    <span class="wv-freq-val" id="wvFreqVal">220 Hz</span>
  </div>
</div>

Step by step

How to Use

  1. 1
    Load the snippetClick "Audio Waveform Tone Visualizer" in the sidebar to load its HTML, CSS, and JS into the editor panels. The preview updates instantly.
  2. 2
    Edit the codeModify any panel — HTML, CSS, or JS. The preview refreshes as you type. Use Reset in each panel header to restore the original.
  3. 3
    Preview on devicesClick the Mobile (375px), Tablet (768px), or Desktop buttons in the preview header to check responsiveness.
  4. 4
    Export in your formatClick "HTML" to download a standalone file, "JSX" for a React component, "Tailwind" for a React + Tailwind CSS component, "Tailwind HTML" for a standalone HTML file with Tailwind CDN, "Vue" for a Vue 3 SFC with <template>/<script setup>/<style scoped>, or "Angular" for a standalone Angular .component.ts file. "Copy all" copies the full code to clipboard.
  5. 5
    Save your versionClick "Save as", type a name, and press Enter. Your snippet saves to IndexedDB and appears in the Saved tab.

Real-world uses

Common Use Cases

Web Audio API learning demos
A minimal, readable example of wiring oscillator, gain, and analyser nodes together.
Synth or DAW-style tools
Reusable as a live monitoring scope for any in-browser audio generation feature.
Interactive audio landing pages
A visually engaging way to demonstrate sound-related products without audio files.
Signal visualization tutorials
Shows how getByteTimeDomainData() translates raw samples into a drawn waveform.

Got questions?

Frequently Asked Questions

Browsers require a real user gesture before allowing an AudioContext to produce sound, as an anti-autoplay policy. The Play Tone button click satisfies that requirement.

Yes — set oscillator.type to "square", "sawtooth", or "triangle" instead of "sine" before or after calling start(), and the drawn waveform shape will change to match.

No. oscillator.frequency.value is updated directly on the live, already-connected oscillator, so the pitch glides to the new value without any audio glitch or restart.