Bootstrap 5 Responsive Navbar with Offcanvas Menu
A floating, frosted header bar with brand, centred links and a call-to-action that collapses into a slide-in offcanvas menu below the large breakpoint. The active link is highlighted and the bar stays pinned on scroll.
<div class="nv-page">
<header class="nv-wrap sticky-top">
<nav class="navbar navbar-expand-lg nv bg-body border rounded-4 shadow-sm mx-auto py-2" aria-label="Main navigation">
<div class="container" style="max-width:1080px">
<a class="navbar-brand d-flex align-items-center gap-2 fw-bold" href="#"><span class="wdw-icon" style="width:2.25rem;height:2.25rem;border-radius:.75rem"><svg width="18" height="18" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2.25" stroke-linecap="round" aria-hidden="true"><path d="M6 5v14M12 9v6M18 3v18"/></svg></span>Acme</a>
<button class="navbar-toggler border-0 shadow-none" type="button" data-bs-toggle="offcanvas" data-bs-target="#nvMenu" aria-controls="nvMenu" aria-label="Open menu"><span class="navbar-toggler-icon"></span></button>
<div class="offcanvas offcanvas-end" tabindex="-1" id="nvMenu" aria-labelledby="nvMenuLabel">
<div class="offcanvas-header"><h2 class="offcanvas-title h5 fw-bold" id="nvMenuLabel">Menu</h2><button type="button" class="btn-close" data-bs-dismiss="offcanvas" aria-label="Close"></button></div>
<div class="offcanvas-body align-items-lg-center">
<ul class="navbar-nav mx-lg-auto gap-lg-1">
<li class="nav-item"><a class="nav-link active" aria-current="page" href="#">About</a></li>
<li class="nav-item"><a class="nav-link" href="#">Products</a></li>
<li class="nav-item"><a class="nav-link" href="#">Services</a></li>
<li class="nav-item"><a class="nav-link" href="#">Work</a></li>
<li class="nav-item"><a class="nav-link" href="#">Contact</a></li>
</ul>
<a href="#" class="btn btn-primary rounded-pill px-4 mt-3 mt-lg-0">Get started</a>
</div>
</div>
</div>
</nav>
</header>
<main class="container py-4 py-lg-5" style="max-width:1080px">
<section class="wdw-aurora rounded-4 p-4 p-lg-5 mb-4 overflow-hidden">
<div class="position-relative" style="max-width:36rem">
<span class="small fw-bold text-uppercase opacity-75" style="letter-spacing:.08em">Responsive header</span>
<h1 class="display-6 fw-bold mt-2">A navbar that collapses into a slide-in menu.</h1>
<p class="opacity-75 mb-4">Links sit inline on wide screens and move into an offcanvas drawer below the large breakpoint. The header stays pinned while you scroll.</p>
<a href="#" class="btn btn-light rounded-pill px-4">Get started</a>
</div>
<div class="row g-3 text-center position-relative mt-4 pt-4 border-top border-light border-opacity-25"><div class="col-4"><div class="fs-2 fw-bold lh-1">5</div><div class="small opacity-75 mt-1">links</div></div><div class="col-4"><div class="fs-2 fw-bold lh-1">1</div><div class="small opacity-75 mt-1">drawer</div></div><div class="col-4"><div class="fs-2 fw-bold lh-1">0</div><div class="small opacity-75 mt-1">scripts</div></div></div>
</section>
<div class="row g-4">
<div class="col-md-4"><div class="wdw-card p-4 h-100"><h2 class="h6 fw-bold">Try it</h2><p class="wdw-muted small mb-0">Resize the window or open this on a phone to use the drawer.</p></div></div>
<div class="col-md-4"><div class="wdw-card p-4 h-100"><h2 class="h6 fw-bold">Stays pinned</h2><p class="wdw-muted small mb-0">Scroll this page: the floating bar stays at the top.</p></div></div>
<div class="col-md-4"><div class="wdw-card p-4 h-100"><h2 class="h6 fw-bold">Keyboard ready</h2><p class="wdw-muted small mb-0">Escape closes the drawer and focus returns to the menu button.</p></div></div>
</div>
<div class="wdw-card p-4 p-lg-5 mt-4"><h2 class="h5 fw-bold">Built on Bootstrap</h2><p class="wdw-muted mb-0">The bar is a standard navbar with an offcanvas menu. Only the pill link states use custom CSS.</p></div>
<div class="wdw-card p-4 p-lg-5 mt-4"><h2 class="h5 fw-bold">Content below the fold</h2><p class="wdw-muted mb-0" style="min-height:14rem">Extra height so you can scroll and watch the header stay put.</p></div>
</main>
</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 */
.nv-page { overflow-x: clip; min-height: 100vh; background: var(--wdw-stage); }
.nv-wrap { padding: .75rem .75rem 0; z-index: 1030; }
.nv { max-width: 1140px; background: color-mix(in srgb, var(--bs-body-bg) 80%, transparent) !important; -webkit-backdrop-filter: blur(12px); backdrop-filter: blur(12px); }
.nv .navbar-brand { color: var(--bs-emphasis-color); }
.nv .nav-link { font-weight: 600; border-radius: 50rem; padding: .5rem 1rem; min-height: 44px; display: flex; align-items: center; }
.nv .nav-link:hover { color: var(--bs-emphasis-color); background: var(--bs-tertiary-bg); }
.nv .nav-link.active { color: var(--bs-primary); background: var(--bs-primary-bg-subtle); }
.nv .navbar-toggler { min-width: 44px; min-height: 44px; }
@media (max-width: 991.98px) { .nv .offcanvas { background: var(--bs-body-bg); } }
function initNavActive() {
const links = document.querySelectorAll('.nv .nav-link');
if (!links.length) return;
links.forEach((link) => link.addEventListener('click', (e) => {
// Demo only: keep placeholder '#' links from jumping; real hrefs navigate normally.
if (link.getAttribute('href') === '#') e.preventDefault();
links.forEach((l) => { l.classList.remove('active'); l.removeAttribute('aria-current'); });
link.classList.add('active');
link.setAttribute('aria-current', 'page');
const oc = document.getElementById('nvMenu');
const inst = oc && bootstrap.Offcanvas.getInstance(oc);
if (inst) inst.hide();
}));
}
initNavActive();
Built on Bootstrap 5.3.8 with plain JavaScript — no jQuery. Supports light and dark mode via data-bs-theme.