Sound Effects Component — Astro
Toggle for play sound on click (Web Audio); off by default for accessibility.
Sound Effects Component
The SoundEffects component is a checkbox that toggles “Play sound on click”. When enabled, a short click sound plays on primary (left) clicks only on links, buttons, tabs, dropdowns, and other interactive elements (with a short throttle so one interaction doesn’t play twice). Off by default for accessibility. The preference is stored in localStorage (key soundEffects). The layout script loads /assets/sfx/click.mp3 then /assets/sfx/click.wav (add your file(s) to public/assets/sfx/, or to src/assets/sfx/ and run pnpm build:css); if neither is found, a built-in Web Audio tone is used.
Add this component
The command below includes <strong>Sound Effects</strong>—run it in your project directory to install this component (and the CSS if needed). No prompts.
Choose your package manager — click a tab to select, then copy the command.
Enable the toggle below, then click any button or link on the page to hear the click sound:
Short click sound when you interact with buttons and links. Off by default.
Usage
Use the component standalone or inside Settings. The component script initializes every [data-sound-effects] checkbox (load/save localStorage.soundEffects).
Usage
Full example for each framework (Astro, Vanilla, Svelte, Vue, React). Switch framework via View as or by clicking a Usage tab—both stay in sync.
Features
- Checkbox “Play sound on click” with optional help text.
- Persists in
localStorage(keysoundEffects:trueorfalse). Default: off (no key orfalse). - The click sound is played by a global script in the layout that listens for primary clicks on buttons, links, tabs, options, and other interactive elements (throttled). The script loads
/assets/sfx/click.mp3then/assets/sfx/click.wav(add topublic/assets/sfx/); if neither is found, a Web Audio tone is used. Include that script (see Layout.astro) for the sound to play when the user has enabled it.