Add Web Audio Feedback to Bootstrap 5 Components – Bootstrap UI Sounds
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.
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 Name | Freq (Hz) | Duration (s) | Waveform | Volume |
|---|---|---|---|---|
click | 800 | 0.05 | sine | 0.28 |
open | 520 | 0.07 | sine | 0.26 |
close | 320 | 0.06 | sine | 0.26 |
expand | 600 | 0.06 | sine | 0.26 |
collapse | 400 | 0.06 | sine | 0.26 |
alert | 660 | 0.06 | sine | 0.24 |
focus | 440 | 0.04 | sine | 0.20 |
change | 550 | 0.045 | sine | 0.22 |
toast | 580 | 0.06 | sine | 0.24 |
detail | 500 | 0.055 | sine | 0.26 |
carouselPrev | 500 | 0.055 | sine | 0.24 |
carouselNext | 660 | 0.055 | sine | 0.24 |
closeButton | 380 | 0.05 | sine | 0.24 |
switchOn | 780 | 0.05 | square | 0.25 |
switchOff | 420 | 0.055 | triangle | 0.23 |
checkboxOn | 650 | 0.05 | square | 0.24 |
checkboxOff | 400 | 0.06 | triangle | 0.22 |
radio | 680 | 0.045 | triangle | 0.23 |
range | 500 | 0.04 | sine | 0.22 |
formInvalid | 280 | 0.10 | triangle | 0.20 |
formValid | 520 | 0.10 | triangle | 0.22 |
The post Add Web Audio Feedback to Bootstrap 5 Components – Bootstrap UI Sounds appeared first on CSS Script.
In a recent interview with IGN, Ken Levine explained why his next game Judas has…
IGN recently spoke to Bioshock developer Ken Levine about his new game Judas and his…
LEGO has announced a major new addition to its line of sets based on The…
In a recent interview with IGN, Ken Levine explained why his next game Judas has…
IGN recently spoke to Bioshock developer Ken Levine about his new game Judas and his…
Magic: The Gathering had a strange 2025. The highs were really high (Final Fantasy, Tarkir:…
This website uses cookies.