Mastering Bootstrap JS Dropdowns: Create Dynamic Menus with Ease
Dropdowns are everywhere — in navigation bars, action menus, profile settings, and more. With Bootstrap’s JavaScript-powered dropdowns, you can add interactive menus that work beautifully on both desktop and mobile devices.
In this guide, we’ll walk through how to use the Bootstrap Dropdown component, including:
-
Markup with built-in behavior
-
JavaScript control
-
Right-aligned, dropdown-on-hover, and responsive tips
Step 1: Include Bootstrap
Use the official Bootstrap 5+ CDN:
Basic Dropdown Markup
✅ No custom JavaScript needed — data-bs-toggle="dropdown" handles everything.
Aligning & Positioning
Right-aligned menu:
Dropup, Dropstart, Dropright:
JavaScript API: Programmatic Control
You can also control dropdowns with JavaScript using Bootstrap’s API.
HTML:
JavaScript:
Dropdown Events
Bootstrap provides custom events:
Open Dropdown on Hover (Custom)
Bootstrap doesn’t support hover-out-of-the-box, but you can add it with a little JS:
✅ Great for desktop UIs — just test on touch devices too.
Accessibility Notes
-
Bootstrap dropdowns support keyboard navigation
-
aria-expandedand roles are handled automatically -
Keep
ulinside the same parent container as the toggle for proper positioning
✅ Use Cases
-
Navigation menus
-
User account menus
-
Sort & filter dropdowns
-
Action buttons on tables/cards
Final Thoughts
Bootstrap’s Dropdown component makes it simple to add responsive, interactive menus without relying on jQuery or external libraries. Whether you’re building a navbar or a user dashboard, dropdowns give your UI flexibility and control.
