Bootstrap 5 Sidebar Toggle Menu
A dashboard shell with a profile card and icon navigation in a sidebar that slides open and closed from an animated menu button, overlaying the page on phones.
<section class="wdw-stage">
<div class="container" style="max-width:1080px">
<div class="wdw-shell wdw-card" id="wdwShell">
<aside class="wdw-side offcanvas-md offcanvas-start" id="wdwSide" tabindex="-1" aria-labelledby="wdwSideTitle">
<div class="offcanvas-header d-md-none pb-0">
<h2 class="offcanvas-title h6 fw-bold" id="wdwSideTitle">Menu</h2>
<button type="button" class="btn-close" data-bs-dismiss="offcanvas" data-bs-target="#wdwSide" aria-label="Close menu"></button>
</div>
<div class="offcanvas-body d-flex flex-column p-3">
<div class="d-flex align-items-center gap-3 p-3 mb-3 rounded-4 bg-body-tertiary">
<img src="https://i.pravatar.cc/96?img=47" width="48" height="48" class="rounded-circle flex-none" alt="Jelena Jovanovic">
<div class="flex-grow-1 overflow-hidden">
<p class="fw-bold mb-0 text-body-emphasis text-truncate">Jelena Jovanovic</p>
<p class="small wdw-muted mb-0">Web developer</p>
</div>
</div>
<nav aria-label="Sidebar">
<p class="wdw-eyebrow px-2 mb-1 text-body-secondary">Main</p>
<ul class="list-unstyled d-grid gap-1 mb-3">
<li><a href="#" class="wdw-side-link is-active" aria-current="page"><svg width="20" height="20" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="1.85" stroke-linecap="round" stroke-linejoin="round" aria-hidden="true"><path d="M3 10.5 12 3l9 7.5V21h-6v-6H9v6H3z"/></svg><span>Overview</span></a></li>
<li><a href="#" class="wdw-side-link"><svg width="20" height="20" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="1.85" stroke-linecap="round" stroke-linejoin="round" aria-hidden="true"><path d="M4 20V10M10 20V4M16 20v-8M22 20H2"/></svg><span>Analytics</span></a></li>
<li><a href="#" class="wdw-side-link"><svg width="20" height="20" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="1.85" stroke-linecap="round" stroke-linejoin="round" aria-hidden="true"><path d="M3 6a2 2 0 0 1 2-2h4l2 3h8a2 2 0 0 1 2 2v9a2 2 0 0 1-2 2H5a2 2 0 0 1-2-2z"/></svg><span>Projects</span></a></li>
</ul>
<p class="wdw-eyebrow px-2 mb-1 text-body-secondary">Workspace</p>
<ul class="list-unstyled d-grid gap-1 mb-0">
<li><a href="#" class="wdw-side-link"><svg width="20" height="20" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="1.85" stroke-linecap="round" stroke-linejoin="round" aria-hidden="true"><path d="M4 5h16v11H9l-5 4z"/></svg><span>Messages</span><span class="badge rounded-pill text-bg-primary ms-auto">4</span></a></li>
<li><a href="#" class="wdw-side-link"><svg width="20" height="20" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="1.85" stroke-linecap="round" stroke-linejoin="round" aria-hidden="true"><path d="M3 5h18v16H3zM3 10h18M8 3v4M16 3v4"/></svg><span>Calendar</span></a></li>
<li><a href="#" class="wdw-side-link"><svg width="20" height="20" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="1.85" stroke-linecap="round" stroke-linejoin="round" aria-hidden="true"><circle cx="12" cy="12" r="3"/><path d="M12 2v3M12 19v3M2 12h3M19 12h3M4.9 4.9 7 7M17 17l2.1 2.1M4.9 19.1 7 17M17 7l2.1-2.1"/></svg><span>Settings</span></a></li>
</ul>
</nav>
<div class="mt-auto pt-3">
<div class="wdw-aurora rounded-4 p-3 mb-3">
<p class="fw-bold mb-1">Go Pro</p>
<p class="small text-white-50 mb-2">Unlock unlimited projects and team seats.</p>
<button type="button" class="btn btn-light btn-sm rounded-pill px-3">Upgrade</button>
</div>
<div class="d-flex gap-2 px-1">
<a href="#" class="wdw-social" aria-label="Instagram"><svg width="18" height="18" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="1.85" aria-hidden="true"><rect x="3" y="3" width="18" height="18" rx="5"/><circle cx="12" cy="12" r="4"/></svg></a>
<a href="#" class="wdw-social" aria-label="YouTube"><svg width="18" height="18" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="1.85" stroke-linejoin="round" aria-hidden="true"><rect x="2.5" y="5.5" width="19" height="13" rx="4"/><path d="m10 9 5 3-5 3z"/></svg></a>
<a href="#" class="wdw-social" aria-label="LinkedIn"><svg width="18" height="18" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="1.85" stroke-linecap="round" aria-hidden="true"><path d="M6 10v8M6 6.5v.01M11 18v-8M11 13a3 3 0 0 1 6 0v5"/></svg></a>
</div>
</div>
</div>
</aside>
<div class="wdw-main">
<header class="wdw-top d-flex align-items-center gap-3 px-3 px-md-4">
<button type="button" class="wdw-burger" id="wdwBurger" aria-label="Close sidebar" aria-expanded="true" aria-controls="wdwSide">
<span></span><span></span><span></span>
</button>
<span class="fw-bold text-body-emphasis">Dashboard</span>
<span class="ms-auto badge rounded-pill bg-primary-subtle text-primary-emphasis">Live</span>
</header>
<div class="p-3 p-md-4">
<p class="wdw-eyebrow mb-1">Overview</p>
<h2 class="wdw-heading h3 mb-3">Good morning, Jelena</h2>
<div class="row g-3 mb-3">
<div class="col-6"><div class="wdw-card-sm p-3 h-100"><p class="small wdw-muted mb-1">Visitors</p><p class="h4 fw-bold text-body-emphasis mb-1">24.8k</p><span class="badge text-success-emphasis rounded-pill bg-success-subtle">+12%</span></div></div>
<div class="col-6"><div class="wdw-card-sm p-3 h-100"><p class="small wdw-muted mb-1">Revenue</p><p class="h4 fw-bold text-body-emphasis mb-1">$9.4k</p><span class="badge text-success-emphasis rounded-pill bg-success-subtle">+21%</span></div></div>
</div>
<div class="wdw-card-sm p-3 p-md-4">
<div class="d-flex justify-content-between align-items-center mb-3"><span class="fw-semibold text-body-emphasis">Weekly traffic</span><span class="small wdw-muted">Last 7 days</span></div>
<div class="wdw-bars" aria-hidden="true"><span style="--h:45%"></span><span style="--h:62%"></span><span style="--h:38%"></span><span style="--h:80%"></span><span style="--h:56%"></span><span class="is-peak" style="--h:92%"></span><span style="--h:70%"></span></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 */
.wdw-shell { --side-w: 270px; --bs-offcanvas-width: 290px; position: relative; display: flex; overflow: hidden; }
@media (min-width: 768px) { .wdw-shell { min-height: 600px; } }
.wdw-side { flex: none; border-right: 1px solid var(--bs-border-color-translucent); }
@media (min-width: 768px) {
.wdw-shell .wdw-side { width: var(--side-w) !important; flex: none; overflow-y: auto; background-color: var(--bs-body-bg) !important; margin-left: 0; transition: margin-left .35s cubic-bezier(.2,.8,.2,1), visibility 0s; }
.wdw-shell.is-collapsed .wdw-side { margin-left: calc(var(--side-w) * -1); visibility: hidden !important; transition: margin-left .35s cubic-bezier(.2,.8,.2,1), visibility 0s .35s; }
}
.wdw-main { flex: 1 1 0; min-width: 0; overflow: hidden; align-self: stretch; background: var(--bs-tertiary-bg); }
.wdw-top { height: 64px; background: var(--bs-body-bg); border-bottom: 1px solid var(--bs-border-color-translucent); }
.wdw-side-link { display: flex; align-items: center; gap: .75rem; min-height: 44px; padding: 0 .875rem; border-radius: .75rem; color: var(--bs-secondary-color); font-weight: 600; text-decoration: none; transition: background-color .15s, color .15s; }
.wdw-side-link:hover { background: var(--bs-tertiary-bg); color: var(--bs-emphasis-color); }
.wdw-side-link.is-active { background: var(--bs-primary-bg-subtle); color: var(--bs-primary); }
.wdw-side-link:focus-visible, .wdw-social:focus-visible, .wdw-burger:focus-visible { outline: 2px solid var(--bs-primary); outline-offset: 2px; }
.wdw-social { width: 44px; height: 44px; display: inline-flex; align-items: center; justify-content: center; border-radius: 50%; color: var(--bs-secondary-color); border: 1px solid var(--bs-border-color); transition: color .15s, border-color .15s; }
.wdw-social:hover { color: var(--bs-primary); border-color: var(--bs-primary); }
.wdw-burger { position: relative; width: 44px; height: 44px; border: 0; border-radius: .75rem; background: var(--bs-tertiary-bg); color: var(--bs-emphasis-color); display: inline-flex; flex-direction: column; align-items: center; justify-content: center; gap: 4px; padding: 0; }
.wdw-burger span { width: 18px; height: 2px; border-radius: 2px; background: currentColor; transition: transform .3s, opacity .2s; }
.wdw-shell.is-open .wdw-burger span:nth-child(1) { transform: translateY(6px) rotate(45deg); }
.wdw-shell.is-open .wdw-burger span:nth-child(2) { opacity: 0; }
.wdw-shell.is-open .wdw-burger span:nth-child(3) { transform: translateY(-6px) rotate(-45deg); }
.wdw-bars { display: flex; align-items: flex-end; gap: .75rem; height: 120px; }
.wdw-bars span { flex: 1; height: var(--h); border-radius: .5rem .5rem .25rem .25rem; background: rgba(var(--bs-primary-rgb), .3); }
.wdw-bars span.is-peak { background: var(--bs-primary); }
.flex-none { flex: none; }
@media (prefers-reduced-motion: reduce) { .wdw-shell .wdw-side, .wdw-burger span { transition: none; } }
function initSidebarToggle() {
var shell = document.getElementById('wdwShell');
var btn = document.getElementById('wdwBurger');
var side = document.getElementById('wdwSide');
if (!shell || !btn || !side) return;
var mq = window.matchMedia('(min-width: 768px)');
var drawer = bootstrap.Offcanvas.getOrCreateInstance(side);
var collapsed = false; // desktop state
function render(open) {
shell.classList.toggle('is-open', open);
shell.classList.toggle('is-collapsed', mq.matches && !open);
side.inert = mq.matches && !open; // keep the hidden sidebar out of the tab order
btn.setAttribute('aria-expanded', open ? 'true' : 'false');
btn.setAttribute('aria-label', open ? 'Close sidebar' : 'Open sidebar');
}
btn.addEventListener('click', function () {
if (mq.matches) { collapsed = !collapsed; render(!collapsed); }
else drawer.toggle();
});
side.addEventListener('shown.bs.offcanvas', function () { render(true); });
side.addEventListener('hidden.bs.offcanvas', function () { render(false); });
mq.addEventListener('change', function () { render(mq.matches ? !collapsed : false); });
side.querySelectorAll('.wdw-side-link').forEach(function (link) {
link.addEventListener('click', function (e) {
e.preventDefault();
side.querySelectorAll('.wdw-side-link').forEach(function (l) { l.classList.remove('is-active'); l.removeAttribute('aria-current'); });
link.classList.add('is-active');
link.setAttribute('aria-current', 'page');
if (!mq.matches) drawer.hide();
});
});
render(mq.matches);
}
initSidebarToggle();
Built on Bootstrap 5.3.8 with plain JavaScript — no jQuery. Supports light and dark mode via data-bs-theme.