What are Bootstrap menus?
In practice the phrase covers anything built from Bootstrap’s predefined classes and data attributes that opens, closes or collapses a list of links.
These pieces belong to the wider Bootstrap component library, which also holds cards, modals and forms. Bootstrap’s JavaScript docs call data attributes the preferred way to switch plugins on, so most menus need no hand-written script.
- The navbar is the site header, with a brand, links and a toggler that collapses at a set breakpoint.
- A nav is a flexbox link list that can be restyled into tabs, pills or an underline variant.
- Dropdown overlays a toggleable list of links, opened by click.
- Offcanvas gives you a sidebar panel that slides in from the left, right, top or bottom edge of the viewport.
- List group stacks items, and its links and buttons can act as navigation.
In Bootstrap 5, “menu” is an umbrella term and not a class name. The v6.0.0-alpha.1 release notes on GitHub rename the Dropdown component to Menu, and the v6 docs use .menu and .menu-item classes.
Version 6 is still an alpha as of October 2026, so everything below assumes Bootstrap 5.3 unless it says otherwise.
None of these components is an ARIA menu. The 5.3 docs reserve the WAI-ARIA role=”menu” widget for application-like menus that trigger actions, and Bootstrap does not add those roles for you.
Which Bootstrap menu component fits which job?
Site-wide links go in a navbar. A link list behind a button is a dropdown, and a slide-in panel is offcanvas. Secondary and sidebar navigation usually ends up as a nav or a list group.
| Component | Job | JavaScript | Small-screen behavior |
|---|
| Navbar | Site header, primary links | Collapse plugin for the toggler | Collapses below the navbar-expand breakpoint |
| Dropdown | Link list behind a toggle | Dropdown plugin | Opens on click at any width |
| Offcanvas | Slide-in panel | Offcanvas plugin | Hidden until toggled; offcanvas-lg shows it inline from lg up |
| Nav | Secondary or tab-style links | None for links; Tab plugin for panes | No built-in collapse; use flex utilities |
| List group | Stacked items, sidebar menus | None for links; Tab plugin for panes | No built-in collapse; horizontal variants per breakpoint |
The navbar carries primary website navigation and collapses behind a toggler on its own. Default to it.
Offcanvas earns its place once the mobile menu holds more than links, say search and account controls. It opens over the page with a backdrop that closes it on click, per the offcanvas docs.
A persistent left-hand column is a job for a vertical nav (flex-column) or a list group. A Bootstrap sidebar can pair either one with a responsive offcanvas for small screens.
There’s one combination to avoid. A nav styled as tabs can hold a dropdown visually, but the tab plugin does not support tabbed interfaces where a tab trigger sits inside the dropdown menu. The Bootstrap docs cite usability and accessibility problems as the reason.
How to build a responsive navbar in Bootstrap
Nest the wrapper, container, brand, toggler, collapse region and link list in that order. Skip a layer and either the toggler dies or the layout falls apart.
- Load Bootstrap CSS in the head and the JavaScript bundle (bootstrap.bundle.min.js) before the closing body tag. The 5.3 docs examples pull both from jsDelivr at version 5.3.8.
- Add a nav element with the classes navbar, navbar-expand-lg and bg-body-tertiary.
- Put a div with container-fluid inside it. Bootstrap 5 requires a container within the navbar, according to the v5 migration notes.
- Add the brand as an anchor with navbar-brand. An anchor works best, and the content can be text, an image or both.
- Add a button with navbar-toggler, data-bs-toggle=”collapse”, a data-bs-target pointing at the collapse region, aria-controls, aria-expanded=”false” and aria-label=”Toggle navigation”. Put a span with navbar-toggler-icon inside it.
- Add a div with collapse and navbar-collapse, using the id the toggler targets.
- Inside it, add a ul with navbar-nav, then an li with nav-item and an anchor with nav-link for each page.
Mark the current page with active on the nav-link plus aria-current=”page”. In Bootstrap 5, active can no longer sit on the nav-item, a v4 habit the migration notes list as a breaking change.
The classic breakage is an id mismatch. If data-bs-target says #navbarNav and the collapse div says navbarMain, the toggler opens nothing.
Search forms, centered brands and other layouts are covered in a dedicated Bootstrap navbar tutorial.
How does a Bootstrap navbar collapse on mobile?
Whatever breakpoint sits in the navbar-expand class decides it. Narrower than that, the links hide behind a toggler button. Wider, they sit in a row.
The toggler shows the standard hamburger menu icon, drawn from an SVG background image rather than an icon font.
Breakpoint classes
The collapse point comes from a suffix on navbar-expand: sm, md, lg, xl or xxl, per the Bootstrap 5.3 navbar docs.
- navbar-expand-lg collapses below lg and shows a full row from lg up
- navbar-expand never collapses
- no expand class at all means always collapsed
Count the links before picking one. A short list can stay expanded down to md, while a long one needs xl.
Toggler placement follows the markup. A toggler written after the brand lands on the far right, and writing it first puts it on the left.
A toggler can also control a container outside the navbar, because the Collapse plugin matches the id to data-bs-target. The docs recommend adding JavaScript that moves focus to that container once it opens, since keyboard and assistive technology users otherwise struggle to find it.
Offcanvas navbar
Swap the collapse region for an offcanvas panel and the navbar slides its links in from the edge. The toggler then carries data-bs-toggle=”offcanvas” instead of collapse.
Pair the panel with navbar-expand-lg and it flattens back into a normal row from lg up. Leave the expand class off and the slide-in drawer stays at every width.
- Only one offcanvas shows at a time
- A backdrop closes it on click unless the backdrop option is static
- Esc closes it by default
- Body scrolling stays off while it is open, unless data-bs-scroll is set
A dark navbar does not darken the panel. Set data-bs-theme=”dark” on a wrapper or add text-bg-dark to the offcanvas, or the text turns illegible on the light background.
Scrolling long menus
By default a scrolling navbar menu is capped at 75vh, according to the navbar docs.
Add navbar-nav-scroll to a navbar-nav and the open menu scrolls instead of running off the screen. Override the height with a local CSS custom property when 75vh is wrong for your layout.
There’s a catch, though. Setting overflow-y to auto turns overflow-x into auto as well, so some horizontal content gets cropped.
JavaScript requirements for Bootstrap menus
The navbar toggler runs on the Collapse plugin, and anything that overlays links runs on Dropdown. Drawers use Offcanvas. With JavaScript disabled the plugins have no fallback, so a toggler does nothing (Bootstrap 5.3 JavaScript docs).
Bootstrap 5.0.0 dropped the jQuery dependency, and the 5.3 docs treat jQuery as optional. Bootstrap 4 builds are the ones that still lean on it.
Loading the code comes down to a few options.
- bootstrap.bundle.min.js is one file with Popper included
- bootstrap.min.js plus Popper, with Popper loaded first and only one of bootstrap.js or bootstrap.min.js on the page
- ESM in the browser, which needs an import map to resolve Popper
Popper positions dropdowns, popovers and tooltips. It does not position dropdowns inside a navbar, where Bootstrap sets data-bs-popper=”static” and skips dynamic placement, as the v5 migration notes describe.
Attributes do the wiring. data-bs-toggle picks the plugin (collapse, dropdown or offcanvas), and data-bs-target points a toggler at the element it controls by selector.
Why menus stop working
- If no JavaScript is loaded, the CSS still renders the navbar but the toggler is dead.
- Bootstrap 4 attributes stop responding in version 5, which namespaces them as data-bs-toggle and data-bs-target, so data-toggle markup does nothing.
- data-bs-target must be a valid selector that matches the collapse region’s id, and special characters need escaping.
- A single element takes one set of data attributes, so a toggler cannot also trigger a tooltip.
- Bootstrap’s docs warn that React, Vue and Angular mutate the same DOM, which leaves dropdowns stuck open, and point to React Bootstrap and ng-bootstrap instead.
Check the loaded scripts first, then the target ids.
Adding a dropdown menu to a navbar
The structure is a nav-item with the dropdown class wrapping a nav-link toggle and a dropdown-menu list. The docs ask for separate nested elements for nav-item and nav-link because the menu needs a wrapper to position against.
The plugin behind the Bootstrap dropdown component also drives standalone button dropdowns, so most of what follows applies outside navbars too. Dropdowns open on click, not hover, which the docs call an intentional design decision.
- Start with an anchor carrying nav-link, dropdown-toggle, role=”button”, data-bs-toggle=”dropdown” and aria-expanded=”false” as the toggle.
- The menu itself is a ul with dropdown-menu, and each entry is an li wrapping an anchor with dropdown-item.
- For a divider, put an hr with dropdown-divider inside its own li.
Directions and alignment
Direction classes go on the parent element, alignment classes on the menu itself.
| Class | Menu opens |
|---|
| dropup | Above the toggle |
| dropend | To the right of the toggle |
| dropstart | To the left of the toggle |
| dropdown-center | Centered below the toggle |
Directions flip in RTL layouts, so dropstart appears on the right there. Add dropdown-menu-end to right-align a menu.
Responsive variants such as dropdown-menu-lg-end need data-bs-display=”static” outside a navbar. Inside one you can skip the attribute, because Popper is not in play.
Auto-close behavior
By default a dropdown closes on any click, inside or outside. The data-bs-auto-close attribute changes that.
- true is the default, and a click inside or outside closes the menu
- inside closes it only on clicks inside
- outside closes it only on clicks outside
- false leaves closing to the toggle or a script
A form inside a dropdown needs outside, otherwise the first click in a field shuts the menu. The 5.3 docs use exactly that setting in their login form example.
Fixed and sticky navbar placement
Use sticky-top when the navbar should scroll with the page and then stay put at the top, and fixed-top when it should be pinned to the viewport from the first pixel. Sticky costs nothing in layout, while fixed does.
- fixed-top pins the bar edge to edge at the top of the viewport and pulls it out of the page flow
- fixed-bottom does the same at the bottom edge
- sticky-top scrolls with the page until it reaches the top, then stays
- sticky-bottom scrolls until it reaches the bottom, then stays
A fixed navbar reserves no space, so page content slides underneath it. The navbar docs suggest padding-top on the body to compensate.
A sticky navigation bar keeps its place in the flow, so there is nothing to compensate for. That makes it the lower-maintenance default for most sites.
Responsive variants such as sticky-md-top pin the bar only from that breakpoint up. On phones the bar scrolls away with the page instead of holding screen space.
Placement breaks in two common ways.
- A parent with overflow set to hidden, scroll or auto becomes the scroll container, and a sticky navbar sticks to that parent instead of the viewport (MDN)
- A transform, perspective or filter on an ancestor makes that ancestor the containing block, so fixed-top stops pinning to the viewport (MDN)
Stacking order matters too. Bootstrap’s default scale puts sticky at 1020 and fixed at 1030, with offcanvas at 1045 above both, per the 5.3 z-index docs.
A custom banner with a higher z-index covers the navbar. If you change one value in the scale, the docs advise changing all of them.
Navbar theming with color modes and CSS variables
Set data-bs-theme=”dark” on the navbar to switch it to the dark color mode. The attribute arrived in Bootstrap 5.3.0 and replaces the deprecated navbar-dark class.
| Old class | Current approach | Deprecated in |
|---|
| navbar-dark | data-bs-theme=”dark” on the navbar or a parent | 5.3.0 |
| navbar-light | Default light navbar variables | 5.2.0 |
| dropdown-menu-dark | data-bs-theme=”dark” on the dropdown or a wrapper | 5.3.0 |
| btn-close-white | data-bs-theme=”dark” on the button or a parent | 5.3.0 |
The attribute is scoped. On the html element it applies to the whole page, and on a navbar it applies to that navbar and what sits inside it.
A dark bar on a light page is one attribute plus a background utility such as bg-primary.
Since 5.2.0, navbar colors live in CSS variables scoped to the navbar base class. Override them on your own selector instead of rewriting Bootstrap’s rules.
- –bs-navbar-color and –bs-navbar-hover-color for link states
- –bs-navbar-brand-color for the brand
- –bs-navbar-toggler-icon-bg for the hamburger image
If you compile from source, Sass variables such as $navbar-dark-color set the defaults those CSS variables start from.
Custom colors need a check. Bootstrap’s accessibility docs warn that some default palette combinations fall below the WCAG 2.2 text ratio of 4.5:1, and some below the non-text ratio of 3:1, particularly on light backgrounds.
Run a color contrast test on link, hover and toggler colors against whichever bg-* class you picked.
Are Bootstrap menus accessible by default?
Partly. Bootstrap supplies keyboard movement, focus handling and reduced-motion support, and leaves the semantic wrapper around a navigation menu to the author.
Bootstrap’s own accessibility page puts the overall web accessibility of a project largely on the author’s markup, styling and scripting. It adds that generic components often need extra roles and attributes.
Some of it comes built in.
- Cursor keys move through dropdown items, and Esc closes the menu
- Collapse and offcanvas transitions follow the prefers-reduced-motion setting
- The offcanvas plugin adds role=”dialog” itself
The rest is yours to add.
- A nav element or role=”navigation” on the container, never on the ul itself
- aria-labelledby on every offcanvas, pointing at its title
- aria-controls on dropdown toggles, which the docs’ examples leave out
- No tab roles on a nav styled as tabs, because role=”tablist”, role=”tab” and role=”tabpanel” belong to dynamic tab interfaces only
The W3C’s ARIA pattern guidance takes a different route for site navigation than the menu role. Its disclosure navigation example (page updated January 2026) pairs buttons carrying aria-expanded and aria-controls with plain link lists, because typical site navigation does not need menu-widget keyboard behavior.
Bootstrap’s navbar dropdowns already match that shape, minus aria-controls.
The v6 alpha Menu goes further. It adds aria-haspopup=”true” to submenu triggers, keeps aria-expanded in sync, and supports Home, End and arrow-key movement, according to the v6 Menu docs.
Multilevel dropdowns and hover menus: what Bootstrap 5 does not support
Bootstrap 5.3 documents no multilevel dropdown, and its dropdown toggle cannot double as a link to a parent page. Both limits are old, and both trace back to deliberate decisions.
- Nested dropdowns were dropped in Bootstrap 3
- A maintainer reply in GitHub issue 21026 (October 27, 2016) says they have not been supported since v3
- The Bootstrap 5.3 dropdown docs describe single-level menus only
The same thread gives the reasons as poor behavior on mobile and the JavaScript needed to get desktop right. It also records the maintainer’s position that the omission has not stopped anyone from building their own.
The working examples tend to rely on extra CSS and JavaScript, as the Pinegrow tutorial for Bootstrap 4 shows.
The workarounds carry their own costs.
- Pinegrow’s Bootstrap 4 recipe pastes in custom CSS and a jQuery script, then adds a second script version to fix a “$ is not a function” error
- In a support thread for MDB, a library built on Bootstrap, tapping a submenu on 5.3 closes the whole dropdown on mobile
- One commenter in the issue thread suggests submenus that also expand on click or tap, not only on hover, so they keep working on touch screens
Hover is a separate story. The 2012 post by Bootstrap co-creator Mark Otto (February 27, 2012) explains the choice. Dropdowns opened on hover before the project went open source, and the team switched because the menu vanishes as soon as the cursor leaves.
His rule is that hover indicates and click acts. Opening a dropdown is an explicit action, which is also why the toggle cannot be a link to its own page.
Hover menus are still easy to build outside the framework, and plenty of pure CSS dropdown menus open on :hover with no script. Any hover-triggered menu still needs a way to dismiss it without moving the pointer, such as Esc, to meet WCAG 1.4.13, as the W3C’s navigation example shows.
If the site architecture truly needs three levels, a purpose-built JavaScript menu beats stacking hacks on Bootstrap’s dropdown plugin. Flattening to one level plus a collapse-based mobile menu is the cheaper fix for everything else.
Bootstrap 5.3 or Bootstrap 6 alpha: which version should menus use?
Build production menus on Bootstrap 5.3. The first Bootstrap 6 alpha shipped on October 8, 2026, and the maintainers say things can still change meaningfully before beta (official Bootstrap blog).
- Bootstrap 5.3.8 is the latest stable, released August 25, 2025, with v5.4.0 planned before any end-of-life date for v5 is announced
- Bootstrap 4.6.2 was the final v4 release, and v4 reached end of life on January 1, 2023 (Bootstrap’s end-of-life page)
- Bootstrap 6.0.0-alpha.1 is a preview, with more alphas ahead of beta and release candidates
| Item | Bootstrap 5.3 | Bootstrap 6 alpha |
|---|
| Dropdown component | Dropdown: dropdown-menu, dropdown-item | Menu: menu, menu-item |
| Toggle and direction | data-bs-toggle=”dropdown”; dropup, dropend, dropstart | data-bs-toggle=”menu”; data-bs-placement |
| Positioning library | Popper | Floating UI |
| Mobile navbar menu | collapse navbar-collapse, or offcanvas | Drawer, built on a native dialog element |
| Nested menus | Not supported | submenu class, hover and click |
Navbars take a direct hit too. navbar-expand-md becomes md:navbar-expand, navbar-light and navbar-dark are removed, and the breakpoint scale moves: lg grows from 992px to 1024px and xxl becomes 2xl (v6 migration guide).
The same guide lists navbar expansion among the features that now respond to a parent query container instead of the viewport.
The v6 submenu answers the limits above directly. Submenus support hover and click activation and keyboard navigation, and they can be nested to multiple levels.
Below 576px they stack over the parent menu with a back button instead of flying out sideways, per the v6 Menu docs.
The larger cost is the browser floor. Bootstrap 6 requires Chrome and Edge 130, Firefox 132 and Safari 18, against Chrome and Firefox 60 and Safari 12 for v5, and it ships no fallbacks, prefixes or polyfills below that line.
That floor rewrites your cross-browser compatibility checklist. Check your analytics before planning a migration.
My rule is simple.
- Anything shipping to users stays on Bootstrap 5.3
- A site still on Bootstrap 4 should move to 5.3 first
- A prototype that needs native submenus can try the Bootstrap 6 alpha, on a branch you can throw away
Common Questions About Bootstrap Menus
How do I center or right-align navbar links?
Add ms-auto to the navbar-nav list to push links to the right, or mx-auto to center them. The navbar docs point to flex and spacing utilities for alignment, and standalone nav components take justify-content-center or justify-content-end instead.
How do I close the mobile menu after clicking a link?
Call hide() on the Collapse instance from a click handler on the nav links, for example through bootstrap.Collapse.getOrCreateInstance.
A normal page load closes the menu on its own, so the handler only matters for same-page anchors and single-page apps.
Can a Bootstrap navbar include a search form?
Yes. Place a form with the d-flex class and role=”search” inside the navbar, holding an input with form-control and a submit button.
Put it inside the collapse region so it folds away on small screens, or outside the region to keep it visible at every width.
Does Bootstrap have a mega menu?
No. Bootstrap 5.3 ships no mega menu component, but its dropdown menus accept custom content such as text and forms, so the usual build places a grid of columns inside one.
Expect custom CSS for full-width placement, and test the collapsed layout on small screens.
Testing Bootstrap Menus Before Launch
Run the checks on the production build, and start with the keyboard, then touch, then a screen reader.
Keyboard goes first because it needs no extra device and exposes focus order and Escape behavior early.
- Tab, Enter, Space and Escape through every dropdown
- Toggle button and tap targets on a real phone
- Expanded and collapsed states announced by a screen reader
The cost is time. Manual passes on three input types take longer than one automated scan, and a scan cannot judge how a state change sounds to a listener.
As of October 29, 2026, a Bootstrap 6 beta release would change this test plan, since the renamed Menu and Drawer components need their own pass.