Bootstrap 5 Off-Canvas Menu with Slide-In Navigation
A slide-in navigation panel opened from a menu button, with icon links, search and an account card. The panel can be dismissed with Esc, the backdrop or the close button and can slide from either side.
<section class="wdw-stage">
<div class="container" style="max-width: 1040px">
<div class="wdw-card overflow-hidden">
<header class="d-flex align-items-center justify-content-between gap-3 px-3 px-md-4 py-3 border-bottom">
<div class="d-flex align-items-center gap-3">
<button class="btn btn-outline-primary rounded-pill px-3" type="button" data-bs-toggle="offcanvas" data-bs-target="#siteMenu" aria-controls="siteMenu">
<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>
<span>Menu</span>
</button>
<span class="fw-bold fs-5 text-body-emphasis d-none d-sm-inline">Northwind</span>
</div>
<a href="#" class="btn btn-primary rounded-pill px-4">Get started</a>
</header>
<div class="row g-0 align-items-stretch">
<div class="col-lg-7 p-4 p-md-5">
<span class="wdw-eyebrow mb-3">Off-canvas navigation</span>
<h1 class="wdw-heading display-5 mb-3">A menu that slides in, then gets out of the way.</h1>
<p class="wdw-muted fs-5 mb-4">Tap the menu button to open a side panel with your main links, search and account actions. Press Esc, tap the backdrop or hit the close button to dismiss it.</p>
<div class="d-flex flex-wrap gap-2">
<button class="btn btn-primary rounded-pill px-4 flex-fill flex-sm-grow-0" type="button" data-bs-toggle="offcanvas" data-bs-target="#siteMenu" aria-controls="siteMenu">Open menu</button>
<button class="btn btn-outline-primary rounded-pill px-4 flex-fill flex-sm-grow-0" type="button" id="menuSideToggle" aria-pressed="false">Switch to right side</button>
</div>
</div>
<div class="col-lg-5 wdw-aurora p-4 p-md-5 d-flex flex-column align-items-center justify-content-center gap-3">
<div class="wdw-mini bg-body text-body rounded-4 shadow-lg p-3 w-100" aria-hidden="true">
<div class="d-flex align-items-center justify-content-between mb-3">
<span class="fw-bold">Northwind</span>
<span class="wdw-mini-x">×</span>
</div>
<div class="wdw-mini-search rounded-pill px-3 py-2 small mb-2">Search the site</div>
<div class="d-flex flex-column gap-1 small fw-semibold">
<div class="rounded-3 px-3 py-2 text-bg-primary">Home</div>
<div class="rounded-3 px-3 py-2">Projects</div>
<div class="rounded-3 px-3 py-2 d-flex justify-content-between">Messages <span class="badge rounded-pill text-bg-primary">4</span></div>
<div class="rounded-3 px-3 py-2">Settings</div>
</div>
<div class="d-flex align-items-center gap-2 mt-3 p-2 rounded-3 bg-body-tertiary">
<span class="rounded-circle bg-primary-subtle d-inline-block" style="width:28px;height:28px"></span>
<span class="small fw-semibold">Mara Ellis</span>
</div>
</div>
<div class="d-flex gap-2 w-100">
<div class="wdw-key rounded-4 p-2 px-3 flex-fill small"><strong>Esc</strong> closes</div>
<div class="wdw-key rounded-4 p-2 px-3 flex-fill small"><strong>Tab</strong> stays inside</div>
</div>
</div>
</div>
</div>
</div>
<div class="offcanvas offcanvas-start wdw-menu" tabindex="-1" id="siteMenu" aria-labelledby="siteMenuLabel">
<div class="offcanvas-header px-4 pt-4">
<h2 class="offcanvas-title fs-5 fw-bold" id="siteMenuLabel">Northwind</h2>
<button type="button" class="btn-close" data-bs-dismiss="offcanvas" aria-label="Close menu"></button>
</div>
<div class="offcanvas-body px-4 d-flex flex-column gap-4">
<label class="visually-hidden" for="menuSearch">Search</label>
<input id="menuSearch" type="search" class="form-control" placeholder="Search the site">
<nav aria-label="Main">
<ul class="nav nav-pills flex-column gap-1">
<li class="nav-item"><a class="nav-link active d-flex align-items-center gap-3" href="#" aria-current="page"><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="M3 11l9-8 9 8v9a1 1 0 0 1-1 1h-5v-6H9v6H4a1 1 0 0 1-1-1z"/></svg>Home</a></li>
<li class="nav-item"><a class="nav-link d-flex align-items-center gap-3" href="#"><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"><rect x="3" y="3" width="7" height="7" rx="1.5"/><rect x="14" y="3" width="7" height="7" rx="1.5"/><rect x="3" y="14" width="7" height="7" rx="1.5"/><rect x="14" y="14" width="7" height="7" rx="1.5"/></svg>Projects</a></li>
<li class="nav-item"><a class="nav-link d-flex align-items-center gap-3" href="#"><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"><circle cx="9" cy="8" r="3.5"/><path d="M2.5 20a6.5 6.5 0 0 1 13 0M16 4.5a3.5 3.5 0 0 1 0 7M18 14a6.5 6.5 0 0 1 3.5 6"/></svg>Team</a></li>
<li class="nav-item"><a class="nav-link d-flex align-items-center gap-3" href="#"><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="M4 5h16v11H8l-4 4z"/></svg>Messages<span class="badge rounded-pill text-bg-primary ms-auto">4</span></a></li>
<li class="nav-item"><a class="nav-link d-flex align-items-center gap-3" href="#"><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"><circle cx="12" cy="12" r="3"/><path d="M19 12a7 7 0 0 0-.1-1.2l2-1.5-2-3.4-2.3 1a7 7 0 0 0-2-1.2L14.2 3h-4l-.4 2.7a7 7 0 0 0-2 1.2l-2.3-1-2 3.4 2 1.5a7 7 0 0 0 0 2.4l-2 1.5 2 3.4 2.3-1a7 7 0 0 0 2 1.2l.4 2.7h4l.4-2.7a7 7 0 0 0 2-1.2l2.3 1 2-3.4-2-1.5c.1-.4.1-.8.1-1.2z"/></svg>Settings</a></li>
</ul>
</nav>
<div class="mt-auto d-flex align-items-center gap-3 p-3 rounded-4 bg-body-tertiary">
<img src="https://i.pravatar.cc/80?img=47" width="44" height="44" class="rounded-circle" alt="Profile photo of Mara Ellis">
<div class="lh-sm"><div class="fw-semibold">Mara Ellis</div><small class="wdw-muted">[email protected]</small></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-menu { --bs-offcanvas-width: 320px; border: 0; box-shadow: var(--wdw-shadow); }
.wdw-menu .nav-link { min-height: 44px; border-radius: .75rem; font-weight: 600; }
.wdw-menu .nav-link:not(.active):hover { background: var(--bs-tertiary-bg); }
.wdw-menu { background: var(--bs-body-bg); }
.wdw-mini { max-width: 260px; }
.wdw-mini-x { font-size: 1.25rem; line-height: 1; color: var(--bs-secondary-color); }
.wdw-mini-search { background: var(--bs-tertiary-bg); color: var(--bs-secondary-color); border: 1px solid var(--bs-border-color); }
.wdw-key { background: rgba(255,255,255,.12); }
function initMenuSide() {
var btn = document.getElementById('menuSideToggle');
var menu = document.getElementById('siteMenu');
if (!btn || !menu) return;
btn.addEventListener('click', function () {
var right = menu.classList.toggle('offcanvas-end');
menu.classList.toggle('offcanvas-start', !right);
btn.setAttribute('aria-pressed', right);
btn.textContent = right ? 'Switch to left side' : 'Switch to right side';
});
}
initMenuSide();
Built on Bootstrap 5.3.8 with plain JavaScript — no jQuery. Supports light and dark mode via data-bs-theme.