Add Web Audio Feedback to Bootstrap 5 Components – Bootstrap UI Sounds

Category: Javascript | May 12, 2026
Authorcoliff
Last UpdateMay 12, 2026
LicenseMIT
Views0 views
Add Web Audio Feedback to Bootstrap 5 Components – Bootstrap UI Sounds

Bootstrap UI Sounds is a vanilla JavaScript audio feedback library that adds short Web Audio API sound cues to Bootstrap 5 components.

Embed the script into your Bootstrap project and form interactions, modal dialogs, dropdowns, carousels, toast notifications, and validation states all produce subtle tonal sounds on user interaction.

Features:

  • Synthesizes all sounds in the browser using the Web Audio API.
  • Activates globally or scoped to a specific container with one HTML attribute.
  • Distinct tonal presets for 21 interaction types, including separate sounds for switch-on versus switch-off, checkbox checked versus unchecked, carousel previous versus next, and form valid versus invalid states.
  • Range slider volume scales proportionally to the slider’s current value position.
  • Listens for Bootstrap’s own JavaScript events (show.bs.modal, hide.bs.collapse, show.bs.toast, and others) on component-driven interactions.
  • Raw click listeners handle buttons and carousel controls.
  • Uses a MutationObserver to catch dynamically injected alert elements and play the alert sound immediately on DOM insertion.
  • Resumes a suspended AudioContext automatically on first user interaction.

How to use it:

1. Load Bootstrap CSS and JS first, then add the Bootstrap UI Sounds script before the closing </body> tag.

<!-- Bootstrap CSS -->
<link href="/path/to/bootstrap.min.css" rel="stylesheet">
<!-- Your page content here -->
<!-- Bootstrap JS bundle (includes Popper) -->
<script src="/path/to/bootstrap.bundle.min.js"></script>
<!-- Bootstrap UI Sounds — must load after Bootstrap JS -->
<script src="/path/to/js/bootstrap-ui-sounds.js" defer></script>

2. The plugin is off by default. Activate it by adding data-ui-sounds to the <html> tag, the <body> tag, or any container element you want to scope.

<!-- Adding data-ui-sounds to <html> activates sounds for the entire page -->
<html lang="en" data-ui-sounds="true">
<!-- Sounds play only for components inside this container -->
<div class="settings-panel" data-ui-sounds="true">
  <button class="btn btn-primary">Save settings</button>
  <!-- Other Bootstrap components here -->
</div>

3. Available sound presets. The library uses fixed internal presets. Each maps to a specific interaction type. All use the Web Audio API OscillatorNode with a gain envelope.

Preset NameFreq (Hz)Duration (s)WaveformVolume
click8000.05sine0.28
open5200.07sine0.26
close3200.06sine0.26
expand6000.06sine0.26
collapse4000.06sine0.26
alert6600.06sine0.24
focus4400.04sine0.20
change5500.045sine0.22
toast5800.06sine0.24
detail5000.055sine0.26
carouselPrev5000.055sine0.24
carouselNext6600.055sine0.24
closeButton3800.05sine0.24
switchOn7800.05square0.25
switchOff4200.055triangle0.23
checkboxOn6500.05square0.24
checkboxOff4000.06triangle0.22
radio6800.045triangle0.23
range5000.04sine0.22
formInvalid2800.10triangle0.20
formValid5200.10triangle0.22

Alternatives:

You Might Be Interested In:


Leave a Reply