Bootstrap 5 Responsive Sidebar Navigation
An app shell with a collapsible sidebar navigation that sits beside the content on desktop and slides over it with a scrim on phones.
<section class="wdw-stage"><div class="container" style="max-width:1000px">
<div class="shell wdw-card overflow-hidden" id="shell">
<aside class="side offcanvas-md offcanvas-start" id="sidebar" tabindex="-1" aria-labelledby="sideBrand">
<div class="offcanvas-header px-3 pt-3 pb-2"><span class="fw-bold fs-5 d-flex align-items-center gap-2" id="sideBrand"><span class="wdw-icon" style="width:2rem;height:2rem;border-radius:.6rem"><svg width="16" height="16" viewBox="0 0 24 24" fill="currentColor" aria-hidden="true"><path d="M5 3h14a1 1 0 0 1 1 1v17l-8-4-8 4V4a1 1 0 0 1 1-1z"/></svg></span>Project</span>
<button type="button" class="btn-close d-md-none" data-bs-dismiss="offcanvas" data-bs-target="#sidebar" aria-label="Close menu"></button></div>
<div class="offcanvas-body d-flex flex-column p-0">
<ul class="nav nav-pills flex-column gap-1 px-2 pt-2"><li class="nav-item"><a href="#" class="nav-link d-flex align-items-center gap-3 active" aria-current="page"><svg width="18" height="18" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="1.9" stroke-linecap="round" stroke-linejoin="round" aria-hidden="true"><path d="m3 10 9-7 9 7v10a1 1 0 0 1-1 1h-5v-7H9v7H4a1 1 0 0 1-1-1z"/></svg><span>Home</span></a></li><li class="nav-item"><a href="#" class="nav-link d-flex align-items-center gap-3"><svg width="18" height="18" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="1.9" stroke-linecap="round" stroke-linejoin="round" aria-hidden="true"><path d="M3 7a2 2 0 0 1 2-2h4l2 2h8a2 2 0 0 1 2 2v9a2 2 0 0 1-2 2H5a2 2 0 0 1-2-2z"/></svg><span>Projects</span></a></li><li class="nav-item"><a href="#" class="nav-link d-flex align-items-center gap-3"><svg width="18" height="18" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="1.9" stroke-linecap="round" stroke-linejoin="round" aria-hidden="true"><path d="M17 21v-2a4 4 0 0 0-4-4H7a4 4 0 0 0-4 4v2"/><circle cx="10" cy="7" r="4"/><path d="M21 21v-2a4 4 0 0 0-3-3.9M16 3.1a4 4 0 0 1 0 7.8"/></svg><span>Team</span></a></li><li class="nav-item"><a href="#" class="nav-link d-flex align-items-center gap-3"><svg width="18" height="18" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="1.9" stroke-linecap="round" stroke-linejoin="round" aria-hidden="true"><path d="M21 15a2 2 0 0 1-2 2H7l-4 4V5a2 2 0 0 1 2-2h14a2 2 0 0 1 2 2z"/></svg><span>Messages</span></a></li><li class="nav-item"><a href="#" class="nav-link d-flex align-items-center gap-3"><svg width="18" height="18" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="1.9" stroke-linecap="round" stroke-linejoin="round" aria-hidden="true"><circle cx="12" cy="12" r="3"/><path d="M12 2v3M12 19v3M4.9 4.9l2.1 2.1M17 17l2.1 2.1M2 12h3M19 12h3M4.9 19.1 7 17M17 7l2.1-2.1"/></svg><span>Settings</span></a></li></ul>
<div class="mt-auto p-3"><button type="button" class="btn w-100 d-flex align-items-center gap-2 p-2 rounded-4 bg-body-tertiary text-start border-0 dropdown-toggle" aria-label="Account menu"><img src="https://i.pravatar.cc/72?img=12" alt="" width="36" height="36" class="rounded-circle"><span class="lh-sm small text-truncate flex-grow-1"><strong class="d-block">Alex Morgan</strong><span class="text-body-secondary">[email protected]</span></span></button></div>
</div></aside>
<div class="main">
<header class="d-flex align-items-center gap-3 px-3 py-2 border-bottom"><button type="button" class="btn btn-icon-sm rounded-3 border-0 bg-body-tertiary text-body" id="sideToggle" aria-controls="sidebar" aria-expanded="true" aria-label="Toggle menu"><svg width="18" height="18" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" aria-hidden="true"><path d="M4 6h16M4 12h16M4 18h10"/></svg></button>
<nav aria-label="Breadcrumb"><ol class="breadcrumb mb-0 small"><li class="breadcrumb-item">Workspace</li><li class="breadcrumb-item active" aria-current="page" id="crumb">Home</li></ol></nav></header>
<div class="p-3 p-md-4"><div class="row g-3"><div class="col-6 col-lg-3"><div class="wdw-card-sm p-3"><div class="small wdw-muted">Projects</div><div class="d-flex align-items-baseline justify-content-between gap-2"><div class="h4 wdw-heading mb-0">24</div><span class="badge rounded-pill text-bg-success">+12%</span></div></div></div><div class="col-6 col-lg-3"><div class="wdw-card-sm p-3"><div class="small wdw-muted">Tasks</div><div class="d-flex align-items-baseline justify-content-between gap-2"><div class="h4 wdw-heading mb-0">138</div><span class="badge rounded-pill text-bg-success">+8%</span></div></div></div><div class="col-6 col-lg-3"><div class="wdw-card-sm p-3"><div class="small wdw-muted">Members</div><div class="d-flex align-items-baseline justify-content-between gap-2"><div class="h4 wdw-heading mb-0">12</div><span class="badge rounded-pill text-bg-success">+2</span></div></div></div><div class="col-6 col-lg-3"><div class="wdw-card-sm p-3"><div class="small wdw-muted">Uptime</div><div class="d-flex align-items-baseline justify-content-between gap-2"><div class="h4 wdw-heading mb-0">99.9%</div><span class="badge rounded-pill text-bg-danger">-0.1%</span></div></div></div></div>
<div class="row g-3 mt-0 mt-md-1"><div class="col-lg-6"><div class="wdw-card-sm p-3 p-md-4 h-100"><div class="d-flex justify-content-between align-items-center mb-2"><h2 class="h6 mb-0">Tasks completed</h2><span class="small wdw-muted">Last 14 days</span></div>
<svg viewBox="0 0 300 90" class="w-100 spark" role="img" aria-label="Line chart of tasks completed, trending up" preserveAspectRatio="none"><defs><linearGradient id="spk" 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 70 L25 62 L50 66 L75 50 L100 55 L125 40 L150 46 L175 30 L200 38 L225 22 L250 28 L275 12 L300 18 L300 90 L0 90Z" fill="url(#spk)"/><path d="M0 70 L25 62 L50 66 L75 50 L100 55 L125 40 L150 46 L175 30 L200 38 L225 22 L250 28 L275 12 L300 18" fill="none" stroke="currentColor" stroke-width="2.5" stroke-linejoin="round" stroke-linecap="round" vector-effect="non-scaling-stroke"/></svg></div></div>
<div class="col-lg-6"><div class="wdw-card-sm p-3 p-md-4 h-100"><h2 class="h6 mb-2">Recent activity</h2><ul class="list-unstyled m-0"><li class="d-flex align-items-center gap-3 py-2"><img src="https://i.pravatar.cc/64?img=11" alt="" width="32" height="32" class="rounded-circle"><div class="flex-grow-1 small text-truncate">Maya closed 4 tasks</div><span class="small wdw-muted text-nowrap">2m ago</span></li><li class="d-flex align-items-center gap-3 py-2"><img src="https://i.pravatar.cc/64?img=12" alt="" width="32" height="32" class="rounded-circle"><div class="flex-grow-1 small text-truncate">New member joined</div><span class="small wdw-muted text-nowrap">1h ago</span></li><li class="d-flex align-items-center gap-3 py-2"><img src="https://i.pravatar.cc/64?img=32" alt="" width="32" height="32" class="rounded-circle"><div class="flex-grow-1 small text-truncate">Sprint 14 deployed</div><span class="small wdw-muted text-nowrap">3h ago</span></li><li class="d-flex align-items-center gap-3 py-2"><img src="https://i.pravatar.cc/64?img=5" alt="" width="32" height="32" class="rounded-circle"><div class="flex-grow-1 small text-truncate">Alex commented on Design</div><span class="small wdw-muted text-nowrap">Yesterday</span></li></ul></div></div></div></div>
</div></div></div></section>
/* 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 */
.shell { display: flex; height: 560px; position: relative; }
.main { flex: 1; min-width: 0; overflow: auto; background: var(--bs-tertiary-bg); }
.main > header { background: var(--bs-body-bg); }
.btn-icon-sm { width: 40px; height: 40px; padding: 0; }
.spark { height: 150px; color: var(--bs-primary); }
.side { --bs-offcanvas-width: 270px; }
.side .nav-link { padding: .65rem .85rem; border-radius: .875rem; font-weight: 500; font-size: .925rem; }
.side .nav-link:not(.active):hover { background: var(--bs-tertiary-bg); color: var(--bs-emphasis-color); }
.side .nav-link.active { background: var(--bs-primary-bg-subtle); color: var(--bs-primary-text-emphasis); font-weight: 600; }
@media (min-width: 768px) {
.side.offcanvas-md { flex: 0 0 240px; flex-grow: 0; width: 240px; background: var(--bs-body-bg) !important; border-right: 1px solid var(--bs-border-color) !important; transition: margin-left .25s ease; }
.shell.collapsed .side { margin-left: -240px; visibility: hidden !important; }
}
@media (max-width: 767.98px) { .shell { height: 600px; } }
function initSidebar() {
const shell = document.getElementById('shell');
const toggle = document.getElementById('sideToggle');
const side = document.getElementById('sidebar');
if (!shell || !toggle || !side) return;
const mobile = window.matchMedia('(max-width: 767.98px)');
const crumb = document.getElementById('crumb');
function sync() {
const open = mobile.matches ? side.classList.contains('show') : !shell.classList.contains('collapsed');
toggle.setAttribute('aria-expanded', open);
if (!mobile.matches) { if (shell.classList.contains('collapsed')) side.setAttribute('inert', ''); else side.removeAttribute('inert'); }
}
toggle.addEventListener('click', function () {
if (mobile.matches) bootstrap.Offcanvas.getOrCreateInstance(side).toggle();
else shell.classList.toggle('collapsed');
sync();
});
['shown.bs.offcanvas', 'hidden.bs.offcanvas'].forEach(function (ev) { side.addEventListener(ev, sync); });
mobile.addEventListener('change', sync);
side.querySelectorAll('.nav-link').forEach(function (a) {
a.addEventListener('click', function (e) {
e.preventDefault();
side.querySelectorAll('.nav-link').forEach(function (o) { o.classList.remove('active'); o.removeAttribute('aria-current'); });
a.classList.add('active');
a.setAttribute('aria-current', 'page');
if (crumb) crumb.textContent = a.textContent.trim();
if (mobile.matches) bootstrap.Offcanvas.getOrCreateInstance(side).hide();
});
});
sync();
}
initSidebar();
Built on Bootstrap 5.3.8 with plain JavaScript — no jQuery. Supports light and dark mode via data-bs-theme.