Snippets Collapsible

Bootstrap 5 Collapsible Sidebar with Navbar

A responsive admin shell with a collapsible sidebar, expandable submenus and a sticky top bar. On desktop the menu shrinks to icons; on mobile it slides over the page.

Bootstrap 5 No jQuery Sep 2020 2.5K views

<div class="app-shell" id="appShell">
  <aside class="app-sidebar" id="appSidebar" aria-label="Sidebar">
    <a href="#" class="app-brand d-flex align-items-center gap-2 text-decoration-none">
      <span class="wdw-icon app-brand__mark"><svg width="20" height="20" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" aria-hidden="true"><path d="M12 3l9 5-9 5-9-5 9-5z"/><path d="M3 13l9 5 9-5"/></svg></span>
      <span class="fw-bold fs-5 text-body-emphasis side-label">Bootbase</span>
    </a>
    <div class="wdw-eyebrow mt-4 mb-2 px-2">Menu</div>
    <nav aria-label="Main">
      <ul class="nav flex-column gap-1">
        <li>
          <button type="button" class="nav-link side-link side-link--current w-100" title="Dashboard" data-bs-toggle="collapse" data-bs-target="#subDash" aria-expanded="true" aria-controls="subDash">
            <svg width="18" height="18" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="1.75" stroke-linecap="round" stroke-linejoin="round" aria-hidden="true"><rect x="3" y="3" width="7" height="9" rx="1.5"/><rect x="14" y="3" width="7" height="5" rx="1.5"/><rect x="14" y="12" width="7" height="9" rx="1.5"/><rect x="3" y="16" width="7" height="5" rx="1.5"/></svg>
            <span class="side-label">Dashboard</span><svg class="side-caret" width="14" height="14" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" aria-hidden="true"><path d="M6 9l6 6 6-6"/></svg>
          </button>
          <div class="collapse show" id="subDash"><ul class="nav flex-column side-sub">
            <li><a class="nav-link active" href="#" aria-current="page">Overview</a></li><li><a class="nav-link" href="#">Reports</a></li><li><a class="nav-link" href="#">Activity</a></li></ul></div>
        </li>
        <li><a class="nav-link side-link" href="#" title="Users"><svg width="18" height="18" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="1.75" stroke-linecap="round" aria-hidden="true"><circle cx="9" cy="8" r="3.5"/><path d="M2.5 20c.6-3.6 3.2-5.5 6.5-5.5s5.9 1.9 6.5 5.5"/><path d="M16 4.7a3.5 3.5 0 010 6.6M18 14.8c2 .6 3.2 2.3 3.5 5.2"/></svg><span class="side-label">Users</span></a></li>
        <li>
          <button type="button" class="nav-link side-link w-100 collapsed" title="Subscribers" data-bs-toggle="collapse" data-bs-target="#subSubs" aria-expanded="false" aria-controls="subSubs">
            <svg width="18" height="18" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="1.75" stroke-linecap="round" stroke-linejoin="round" aria-hidden="true"><path d="M4 6h16v12H4z"/><path d="M4 7l8 6 8-6"/></svg>
            <span class="side-label">Subscribers</span><svg class="side-caret" width="14" height="14" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" aria-hidden="true"><path d="M6 9l6 6 6-6"/></svg>
          </button>
          <div class="collapse" id="subSubs"><ul class="nav flex-column side-sub"><li><a class="nav-link" href="#">All subscribers</a></li><li><a class="nav-link" href="#">Segments</a></li></ul></div>
        </li>
        <li><a class="nav-link side-link" href="#" title="Timeline"><svg width="18" height="18" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="1.75" stroke-linecap="round" aria-hidden="true"><circle cx="12" cy="12" r="9"/><path d="M12 7v5l3 2"/></svg><span class="side-label">Timeline</span></a></li>
        <li><a class="nav-link side-link" href="#" title="Live chat"><svg width="18" height="18" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="1.75" stroke-linecap="round" stroke-linejoin="round" aria-hidden="true"><path d="M21 12a8 8 0 01-11.6 7.1L4 20l1-4.6A8 8 0 1121 12z"/></svg><span class="side-label">Live chat</span></a></li>
        <li><a class="nav-link side-link" href="#" title="Likes"><svg width="18" height="18" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="1.75" stroke-linejoin="round" aria-hidden="true"><path d="M12 20s-7-4.4-7-10a4 4 0 017-2.6A4 4 0 0119 10c0 5.6-7 10-7 10z"/></svg><span class="side-label">Likes</span></a></li>
        <li><a class="nav-link side-link" href="#" title="Comments"><svg width="18" height="18" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="1.75" stroke-linecap="round" stroke-linejoin="round" aria-hidden="true"><path d="M4 5h16v11H9l-5 4z"/></svg><span class="side-label">Comments</span></a></li>
      </ul>
    </nav>
    <div class="side-cta mt-auto wdw-aurora rounded-4 p-3">
      <div class="fw-bold">Go Pro</div>
      <p class="small mb-3 opacity-75">Unlock reports and team seats.</p>
      <button type="button" class="btn btn-light btn-sm rounded-pill w-100">Subscribe</button>
    </div>
  </aside>
  <div class="app-backdrop" id="appBackdrop"></div>
  <div class="app-main">
    <header class="app-top d-flex align-items-center gap-3 px-3 px-lg-4">
      <button class="btn btn-outline-secondary rounded-circle p-0 app-toggle" id="sidebarToggle" type="button" aria-label="Toggle sidebar" title="Toggle sidebar" aria-controls="appSidebar" aria-expanded="true">
        <svg width="20" height="20" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" aria-hidden="true"><path d="M4 7h16M4 12h16M4 17h10"/></svg>
      </button>
      <nav class="ms-auto" aria-label="Top"><ul class="nav">
        <li><a class="nav-link fw-semibold text-body-emphasis" href="#">Home</a></li><li><a class="nav-link" href="#">Features</a></li><li><a class="nav-link d-none d-sm-block" href="#">Pricing</a></li><li><a class="nav-link d-none d-sm-block" href="#">Contact</a></li></ul></nav>
    </header>
    <main class="p-4 p-lg-5">
      <span class="wdw-eyebrow">Layout</span>
      <h1 class="wdw-heading display-6 mt-1">Collapsible sidebar</h1>
      <p class="wdw-muted lead mb-4">Collapse the menu to icons on desktop, or slide it over the page on small screens. Submenus use Bootstrap's collapse component.</p>
      <div class="row g-3">
        <div class="col-sm-4"><div class="wdw-card-sm p-3"><div class="wdw-muted small">Subscribers</div><div class="h3 wdw-heading mb-0">12,480</div></div></div>
        <div class="col-sm-4"><div class="wdw-card-sm p-3"><div class="wdw-muted small">Open rate</div><div class="h3 wdw-heading mb-0">42.8%</div></div></div>
        <div class="col-sm-4"><div class="wdw-card-sm p-3"><div class="wdw-muted small">New today</div><div class="h3 wdw-heading mb-0">+214</div></div></div>
      </div>
      <div class="row g-3 mt-1">
        <div class="col-lg-7"><div class="wdw-card-sm p-3 h-100">
          <div class="d-flex justify-content-between align-items-center mb-2"><h2 class="h6 fw-bold mb-0">Subscribers, last 12 weeks</h2><span class="badge rounded-pill bg-success-subtle text-success-emphasis">+8.2%</span></div>
          <svg class="app-chart text-primary" viewBox="0 0 400 120" preserveAspectRatio="none" role="img" aria-label="Line chart showing subscriber growth over twelve weeks"><defs><linearGradient id="appArea" x1="0" y1="0" x2="0" y2="1"><stop offset="0" stop-color="currentColor" stop-opacity=".25"/><stop offset="1" stop-color="currentColor" stop-opacity="0"/></linearGradient></defs><path d="M0 95 L36 88 L73 90 L109 70 L145 74 L182 55 L218 60 L255 40 L291 44 L327 24 L364 28 L400 12 V120 H0Z" fill="url(#appArea)" class="text-primary"/><path d="M0 95 L36 88 L73 90 L109 70 L145 74 L182 55 L218 60 L255 40 L291 44 L327 24 L364 28 L400 12" fill="none" stroke="var(--bs-primary)" stroke-width="2.5" stroke-linecap="round" stroke-linejoin="round" vector-effect="non-scaling-stroke"/></svg>
        </div></div>
        <div class="col-lg-5"><div class="wdw-card-sm p-3 h-100">
          <h2 class="h6 fw-bold mb-2">Recent campaigns</h2>
          <table class="table table-sm align-middle mb-0 small"><thead><tr><th scope="col">Campaign</th><th scope="col" class="text-end">Opens</th></tr></thead><tbody>
            <tr><td>Spring launch</td><td class="text-end">48.1%</td></tr><tr><td>Product update</td><td class="text-end">41.7%</td></tr><tr><td>Weekly digest</td><td class="text-end">39.2%</td></tr></tbody></table>
        </div></div>
      </div>
    </main>
  </div>
</div>

Built on Bootstrap 5.3.8 with plain JavaScript — no jQuery. Supports light and dark mode via data-bs-theme.