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.
<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>
/* Web Designer Wall library style — shared base for every Bootstrap 5 snippet.
Indigo accent, Plus Jakarta Sans, soft cards, pill buttons. Works in light and dark. */
@import url("https://fonts.googleapis.com/css2?family=Plus+Jakarta+Sans:wght@400;500;600;700;800&display=swap");
:root,
[data-bs-theme="light"] {
--wdw-font: "Plus Jakarta Sans", system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
--bs-body-font-family: var(--wdw-font);
--bs-primary: #4f46e5;
--bs-primary-rgb: 79, 70, 229;
--bs-primary-text-emphasis: #3730a3;
--bs-primary-bg-subtle: #eef2ff;
--bs-primary-border-subtle: #c7d2fe;
--bs-link-color: #4f46e5;
--bs-link-color-rgb: 79, 70, 229;
--bs-link-hover-color: #4338ca;
--bs-link-hover-color-rgb: 67, 56, 202;
--bs-focus-ring-color: rgba(79, 70, 229, 0.25);
--bs-border-radius: 0.75rem;
--bs-border-radius-lg: 1rem;
--bs-border-radius-xl: 1.25rem;
--wdw-radius-card: 1.25rem;
--wdw-shadow: 0 1px 2px rgba(16, 24, 40, 0.05), 0 16px 40px -16px rgba(16, 24, 40, 0.22);
--wdw-shadow-sm: 0 1px 2px rgba(16, 24, 40, 0.06), 0 4px 12px -4px rgba(16, 24, 40, 0.12);
--wdw-stage: #f5f6fb;
}
[data-bs-theme="dark"] {
--bs-primary: #818cf8;
--bs-primary-rgb: 129, 140, 248;
--bs-primary-text-emphasis: #c7d2fe;
--bs-primary-bg-subtle: rgba(129, 140, 248, 0.14);
--bs-primary-border-subtle: rgba(129, 140, 248, 0.35);
--bs-link-color: #a5b4fc;
--bs-link-color-rgb: 165, 180, 252;
--bs-link-hover-color: #c7d2fe;
--bs-link-hover-color-rgb: 199, 210, 254;
--bs-focus-ring-color: rgba(129, 140, 248, 0.35);
--wdw-shadow: 0 1px 2px rgba(0, 0, 0, 0.4), 0 16px 40px -16px rgba(0, 0, 0, 0.7);
--wdw-shadow-sm: 0 1px 2px rgba(0, 0, 0, 0.4), 0 4px 12px -4px rgba(0, 0, 0, 0.5);
--wdw-stage: #0f1117;
}
body { font-family: var(--wdw-font); -webkit-font-smoothing: antialiased; }
/* Bootstrap compiles its blue into these components; point them at the accent. */
.btn-primary {
--bs-btn-bg: var(--bs-primary); --bs-btn-border-color: var(--bs-primary);
--bs-btn-hover-bg: #4338ca; --bs-btn-hover-border-color: #4338ca;
--bs-btn-active-bg: #3730a3; --bs-btn-active-border-color: #3730a3;
--bs-btn-disabled-bg: var(--bs-primary); --bs-btn-disabled-border-color: var(--bs-primary);
--bs-btn-focus-shadow-rgb: var(--bs-primary-rgb);
}
[data-bs-theme="dark"] .btn-primary { --bs-btn-color: #0f1117; --bs-btn-hover-bg: #a5b4fc; --bs-btn-hover-border-color: #a5b4fc; --bs-btn-hover-color: #0f1117; --bs-btn-active-color: #0f1117; }
.btn-outline-primary {
--bs-btn-color: var(--bs-primary); --bs-btn-border-color: var(--bs-primary);
--bs-btn-hover-bg: var(--bs-primary); --bs-btn-hover-border-color: var(--bs-primary);
--bs-btn-active-bg: var(--bs-primary); --bs-btn-active-border-color: var(--bs-primary);
--bs-btn-focus-shadow-rgb: var(--bs-primary-rgb);
}
.btn { --bs-btn-font-weight: 600; min-height: 44px; display: inline-flex; align-items: center; justify-content: center; gap: .5rem; }
.btn-sm { min-height: 36px; }
.form-control, .form-select { min-height: 44px; border-radius: .75rem; }
.form-control:focus, .form-select:focus, .form-check-input:focus { border-color: rgba(var(--bs-primary-rgb), .6); box-shadow: 0 0 0 .25rem var(--bs-focus-ring-color); }
.form-check-input:checked { background-color: var(--bs-primary); border-color: var(--bs-primary); }
.nav-pills { --bs-nav-pills-link-active-bg: var(--bs-primary); }
.nav { --bs-nav-link-color: var(--bs-secondary-color); --bs-nav-link-hover-color: var(--bs-emphasis-color); }
.pagination { --bs-pagination-active-bg: var(--bs-primary); --bs-pagination-active-border-color: var(--bs-primary); --bs-pagination-color: var(--bs-body-color); --bs-pagination-focus-box-shadow: 0 0 0 .25rem var(--bs-focus-ring-color); }
.progress, .progress-stacked { --bs-progress-bar-bg: var(--bs-primary); }
.list-group { --bs-list-group-active-bg: var(--bs-primary); --bs-list-group-active-border-color: var(--bs-primary); }
.dropdown-menu { --bs-dropdown-link-active-bg: var(--bs-primary); border-radius: .875rem; box-shadow: var(--wdw-shadow-sm); }
.accordion { --bs-accordion-active-bg: var(--bs-primary-bg-subtle); --bs-accordion-active-color: var(--bs-primary-text-emphasis); --bs-accordion-btn-focus-box-shadow: 0 0 0 .25rem var(--bs-focus-ring-color); }
.badge { font-weight: 600; }
/* Library building blocks — use these instead of re-inventing them per snippet. */
.wdw-stage { min-height: 100vh; display: flex; align-items: center; background: var(--wdw-stage); padding-block: 3rem; }
.wdw-card { background: var(--bs-body-bg); border: 1px solid var(--bs-border-color-translucent); border-radius: var(--wdw-radius-card); box-shadow: var(--wdw-shadow); }
.wdw-card-sm { background: var(--bs-body-bg); border: 1px solid var(--bs-border-color-translucent); border-radius: 1rem; box-shadow: var(--wdw-shadow-sm); }
.wdw-aurora { position: relative; color: #fff; background: radial-gradient(60% 55% at 100% 0, #818cf8 0, transparent 70%), radial-gradient(65% 60% at 0 100%, #ec4899 0, transparent 65%), #1e1b4b; }
.wdw-eyebrow { display: inline-block; font-size: .75rem; font-weight: 700; letter-spacing: .08em; text-transform: uppercase; color: var(--bs-primary); }
.wdw-heading { font-weight: 800; letter-spacing: -.02em; color: var(--bs-emphasis-color); }
.wdw-muted { color: var(--bs-secondary-color); }
.wdw-icon { width: 2.75rem; height: 2.75rem; flex: none; display: inline-flex; align-items: center; justify-content: center; border-radius: .875rem; background: var(--bs-primary-bg-subtle); color: var(--bs-primary); }
/* Component */
.app-shell { --side-w: 260px; --side-w-mini: 76px; display: flex; min-height: 100vh; background: var(--wdw-stage); }
.app-sidebar { width: var(--side-w); flex: none; display: flex; flex-direction: column; padding: 1.25rem 1rem; background: var(--bs-body-bg); border-right: 1px solid var(--bs-border-color-translucent); position: sticky; top: 0; height: 100vh; overflow-y: auto; transition: width .25s ease; }
.app-brand__mark { background: var(--bs-primary); color: var(--bs-body-bg); }
.app-main { flex: 1; min-width: 0; }
.app-top { height: 68px; background: var(--bs-body-bg); border-bottom: 1px solid var(--bs-border-color-translucent); position: sticky; top: 0; z-index: 5; }
.app-toggle { width: 44px; height: 44px; }
.app-chart { width: 100%; height: 120px; display: block; }
.side-link { display: flex; align-items: center; gap: .75rem; min-height: 44px; padding: .5rem .75rem; border: 0; background: none; border-radius: .75rem; font-weight: 600; font-size: .9375rem; text-align: left; white-space: nowrap; color: var(--bs-secondary-color); }
.side-link:hover { background: var(--bs-tertiary-bg); color: var(--bs-emphasis-color); }
.side-link--current { color: var(--bs-primary-text-emphasis); background: var(--bs-primary-bg-subtle); box-shadow: inset 3px 0 0 var(--bs-primary); }
.side-link--current:hover { background: var(--bs-primary-bg-subtle); color: var(--bs-primary-text-emphasis); }
.side-link svg { flex: none; }
.side-caret { margin-left: auto; transition: transform .2s; }
.side-link[aria-expanded="true"] .side-caret { transform: rotate(180deg); }
.side-sub { margin: .25rem 0 .5rem 1.45rem; padding-left: .75rem; border-left: 1px solid var(--bs-border-color); }
.side-sub .nav-link { padding: .4rem .75rem; font-size: .875rem; border-radius: .5rem; }
.side-sub .nav-link.active { color: var(--bs-primary-text-emphasis); font-weight: 600; background: var(--bs-primary-bg-subtle); }
.app-backdrop { display: none; }
@media (min-width: 992px) {
.app-shell.is-mini .app-sidebar { width: var(--side-w-mini); }
.app-shell.is-mini .side-label { position: absolute; width: 1px; height: 1px; margin: -1px; padding: 0; overflow: hidden; clip: rect(0,0,0,0); white-space: nowrap; border: 0; }
.app-shell.is-mini .side-caret, .app-shell.is-mini .side-sub, .app-shell.is-mini .side-cta, .app-shell.is-mini .wdw-eyebrow { display: none; }
.app-shell.is-mini .collapse { display: none !important; }
.app-shell.is-mini .side-link { justify-content: center; }
}
@media (max-width: 991.98px) {
.app-sidebar { position: fixed; z-index: 30; left: 0; transform: translateX(-100%); visibility: hidden; transition: transform .25s ease, visibility 0s linear .25s; }
.app-shell.is-open .app-sidebar { transform: none; visibility: visible; transition-delay: 0s; box-shadow: var(--wdw-shadow); }
.app-shell.is-open .app-backdrop { display: block; position: fixed; inset: 0; z-index: 20; background: rgba(var(--bs-emphasis-color-rgb), .5); }
}
function initCollapsibleSidebar() {
const shell = document.getElementById('appShell');
const btn = document.getElementById('sidebarToggle');
const backdrop = document.getElementById('appBackdrop');
const side = document.getElementById('appSidebar');
if (!shell || !btn || !side) return;
const mq = window.matchMedia('(min-width: 992px)');
const focusable = () => side.querySelectorAll('a[href], button:not([disabled])');
const sync = () => {
const open = mq.matches ? !shell.classList.contains('is-mini') : shell.classList.contains('is-open');
btn.setAttribute('aria-expanded', String(open));
if (mq.matches) side.removeAttribute('inert');
else if (open) side.removeAttribute('inert');
else side.setAttribute('inert', '');
};
const closeDrawer = (restore) => {
shell.classList.remove('is-open');
sync();
if (restore) btn.focus();
};
btn.addEventListener('click', () => {
if (mq.matches) { shell.classList.toggle('is-mini'); sync(); return; }
shell.classList.toggle('is-open');
sync();
if (shell.classList.contains('is-open')) { const f = focusable()[0]; if (f) f.focus(); }
});
if (backdrop) backdrop.addEventListener('click', () => closeDrawer(true));
document.addEventListener('keydown', (e) => {
if (!shell.classList.contains('is-open')) return;
if (e.key === 'Escape') { closeDrawer(true); return; }
if (e.key !== 'Tab') return;
const items = [...focusable(), btn];
const first = items[0], last = items[items.length - 1];
if (e.shiftKey && document.activeElement === first) { e.preventDefault(); last.focus(); }
else if (!e.shiftKey && document.activeElement === last) { e.preventDefault(); first.focus(); }
});
/* In icon-only mode, submenus cannot show: expand the sidebar first. */
side.querySelectorAll('[data-bs-toggle="collapse"]').forEach((b) => {
b.addEventListener('click', () => {
if (mq.matches && shell.classList.contains('is-mini')) { shell.classList.remove('is-mini'); sync(); }
}, true);
});
mq.addEventListener('change', () => { shell.classList.remove('is-open'); sync(); });
sync();
}
initCollapsibleSidebar();
Built on Bootstrap 5.3.8 with plain JavaScript — no jQuery. Supports light and dark mode via data-bs-theme.