Skip to content

Sidebar with Nested Collapsible Menu

Dark Bootstrap 5 sidebar with three-level collapsible menu groups, accordion behavior, active link highlight and an off-canvas panel on mobile.

Also known as: multi level sidebar menu, collapsible sidebar navigation, admin dashboard sidebar, nested sidebar menu

Sidebar with Nested Collapsible Menu live demo

Open in new tab

Bootstrap 5 code (HTML, CSS, JS)

A dark, multi-level Bootstrap 5 sidebar where menu groups open and close with the Collapse plugin, up to three levels deep. It suits admin dashboards, SaaS apps, documentation sites and any layout that needs a long, grouped navigation.

How it works

The wrapper .snm-shell is a flex row with two children: .snm-rail and the .snm-main content area. Inside the rail sits aside.snm-sidebar, which uses Bootstrap's responsive offcanvas-lg class. From 992px up it is a normal, sticky column; below that it becomes an off-canvas panel that slides in from the left when the .snm-open hamburger button is pressed, with its own header and close button.

The menu is a list with the id snm-menu. Every item that has children is a button.snm-link with data-bs-toggle="collapse" pointing to a .collapse block that holds a nested ul.snm-sub. Top-level groups carry data-bs-parent="#snm-menu", so opening Projects closes Team or Settings, like an accordion. Deeper groups such as Templates and Billing have no parent, so they open independently. Bootstrap keeps aria-expanded up to date and the CSS rotates the .snm-caret chevron by -90 degrees when a group is closed. Each nested level is indented with margin-left and a thin left border.

The small script listens for clicks on a.snm-link, moves aria-current="page" to the clicked link (which the CSS highlights in the accent color) and closes the off-canvas panel on small screens through bootstrap.Offcanvas.getInstance(). Without the script the collapse groups still work, only the active link no longer moves.

Customization

  • --snm-bg on .snm-shell in style.css: changes the sidebar background on desktop and in the off-canvas panel.
  • --snm-accent: recolors the current link, badges, focus outline and the logo gradient.
  • --snm-width: makes the desktop rail and the mobile panel wider or narrower (default 17.5rem).
  • --snm-indent: controls how far each nested .snm-sub level is shifted to the right.
  • Remove data-bs-parent="#snm-menu" from the top-level .collapse blocks to let several groups stay open at the same time.
  • Add or remove show on a .collapse and set aria-expanded on its button to choose which groups are open on load.
  • Replace offcanvas-lg with offcanvas-md (and d-lg-none on .snm-open with d-md-none) to show the fixed sidebar from 768px.

Use cases

  • Admin dashboards: a dark sidebar groups many pages into collapsible sections up to three levels deep
  • SaaS applications: accordion behavior opens one menu group at a time and highlights the active link
  • Documentation sites: long grouped navigation stays tidy and slides in as an off-canvas panel on phones
  • Back-office tools: independent nested groups such as Templates and Billing open without closing their neighbors

Accessibility

The menu is a nav with aria-label="Main navigation". Group toggles are real button elements with aria-controls and aria-expanded, so screen readers announce whether a group is open; Enter and Space work natively. The current page is marked with aria-current="page" rather than color alone. Icons are aria-hidden. Every link and button shows a 2px outline on :focus-visible. The mobile panel uses aria-labelledby for its title, and Bootstrap traps focus inside it and closes it with Escape. Chevron and hover transitions are disabled under prefers-reduced-motion.

Usage notes

Requires Bootstrap 5.3 (added automatically) and Bootstrap Icons. The ids (snm-sidebar, snm-menu, snm-projects and so on) must be unique, so rename them if you place two sidebars on one page. Remove the preventDefault() call in script.js once the links have real URLs.

Sidebar with Nested Collapsible Menu at a glance

Framework
Bootstrap 5
Code
HTML, CSS, JavaScript
JavaScript
Vanilla JavaScript, no jQuery
Dependencies
Bootstrap 5, Bootstrap Icons
Layout
Responsive, works on mobile, dark design
Category
Sidebars
License
Free for personal and commercial use

Questions about this template

Can I use the Sidebar with Nested Collapsible Menu code for free?

Yes. You can copy or download the code and use it in personal and commercial projects, including client work. No sign-up is needed. Reselling it as part of a component library or template collection is not allowed; see the license.

How do I add it to my website?

Load Bootstrap 5 and Bootstrap Icons from a CDN (the links are under Requirements). Paste the HTML where the component should appear, add the CSS to your stylesheet and load the JavaScript before the closing </body> tag. Download HTML gives you a complete page with everything already linked.

Does it need jQuery or a JavaScript framework?

No. The script is plain vanilla JavaScript, so it works without jQuery, React or Vue. You can still use the markup inside those frameworks.

Does it work on mobile?

Yes. The layout adapts to small screens. Use the Mobile and Tablet buttons above the live demo to check it at phone and tablet width.

Requirements

Add these to your page (already included in the download):

  • <link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/bootstrap@5.3.3/dist/css/bootstrap.min.css">
  • <script src="https://cdn.jsdelivr.net/npm/bootstrap@5.3.3/dist/js/bootstrap.bundle.min.js"></script>
  • <link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/bootstrap-icons@1.11.3/font/bootstrap-icons.min.css">
Sidebar with Nested Collapsible Menu – free Bootstrap 5 sidebar template
Sidebar with Nested Collapsible Menu · free Bootstrap 5 sidebar template

More Sidebars

Icon Sidebar that Expands on Hover – free Pure CSS sidebar template

Icon Sidebar that Expands on Hover

Pure CSS icon rail that widens to reveal labels, section headings and a profile on hover or keyboard focus, with an active link and badge.

Collapsible Dashboard Sidebar – free Tailwind CSS sidebar template

Collapsible Dashboard Sidebar

Dark Tailwind CSS dashboard sidebar with icons, grouped sections, an unread badge and a button that collapses it to an icon rail with tooltips.