Simple Tone Synth Pad — Free HTML CSS JS Snippet

Simple Tone Synth Pad · Misc · Plain HTML, CSS & JS · Live preview

What's included

Features

Ten-pad grid mapped to real musical note frequencies across an octave
Fresh OscillatorNode + GainNode created per pad press for true polyphony
Percussive envelope (fast attack, exponential decay) makes a sustained oscillator sound plucked
Distinct accent color per pad for quick visual identification
Touch and mouse support with touchstart handling for mobile play
Brief scale-and-brighten press animation synced to each triggered note
No external samples, audio files, or synth libraries required
Data-driven pad generation from a single NOTES array

About this UI Snippet

Simple Tone Synth Pad — Playable Note Grid With Web Audio API

Screenshot of the Simple Tone Synth Pad snippet rendered live

This snippet turns a grid of colored buttons into a playable mini-instrument. Each pad is mapped to a note in a C major scale, and clicking or tapping it triggers a freshly synthesized, percussive tone via the Web Audio API — no samples, no audio files, just oscillators and a shaped volume envelope.

A note per pad

The NOTES array pairs ten notes across an octave and a bit (C4 through A5) with their exact frequencies in Hz and a distinct accent color. Each pad in the grid is generated from this array rather than hand-written in the markup, so adding, removing, or retuning notes only requires editing one array.

Making a plucked sound out of a sustained oscillator

An OscillatorNode by itself produces a constant tone for as long as it runs — it doesn't naturally sound "plucked." The percussive character comes entirely from the GainNode envelope in playNote(): gain jumps up almost instantly with an exponential ramp (a fast attack), then decays back down over half a second with a second exponential ramp (the decay), which is what makes a continuous tone read as a short, struck note rather than a held drone.

A fresh oscillator per hit

Every pad press calls playNote() again, which creates a brand new OscillatorNode and GainNode, starts them, and schedules the oscillator to stop shortly after the envelope finishes. This means multiple pads (or the same pad tapped repeatedly) can overlap and sound simultaneously, exactly like a real synth pad controller, since each note lives in its own independent node graph rather than sharing one oscillator.

Visual feedback synced to the sound

Each press toggles a .sp-pressed class that scales the pad down and brightens it briefly, giving immediate tactile visual confirmation that lines up with the short, percussive nature of the sound itself.

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 "Simple Tone Synth Pad" 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 misc component called "Simple Tone Synth Pad" using plain HTML, CSS, and vanilla JavaScript — no framework, no build step.

Requirements:
- Match the structure and behavior of the "Simple Tone Synth Pad" 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="sp-card">
  <div class="sp-head">
    <span class="sp-eyebrow">Synth</span>
    <h2>Tone Pad</h2>
  </div>
  <div class="sp-grid" id="spGrid"></div>
</div>

Step by step

How to Use

  1. 1
    Load the snippetClick "Simple Tone Synth Pad" 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

Browser-based mini instruments
A playable note grid usable as-is or as a starting point for a small web synth.
Web Audio envelope teaching demos
A clear example of shaping a sustained oscillator into a percussive plucked sound.
Music app onboarding or demos
An inviting, tactile interactive element for music-related product pages.
Game sound effect prototyping
Reusable pattern for quickly auditioning short synthesized notes without audio assets.

Got questions?

Frequently Asked Questions

Yes. Each press creates an entirely new OscillatorNode and GainNode pair, so pressing multiple pads in quick succession, or even the same pad rapidly, produces overlapping, independent notes rather than cutting each other off.

The GainNode envelope in playNote() ramps volume up almost instantly and then decays it exponentially over about half a second. That shape — fast attack, quick decay — is what makes a plain oscillator tone perceptually read as a short plucked note.

Edit the NOTES array — add, remove, or retune any {name, freq, color} entry, and the grid, click handlers, and pad rendering all update automatically since the pads are generated from that array.