Bootstrap 5 Sticky Slider Navigation with Scroll Spy
A page layout with a sticky tab bar whose sliding indicator follows the section in view, and tabs that glide to their section.
<div class="ssn" id="ssn">
<header class="ssn-hero wdw-aurora d-flex align-items-center text-center">
<div class="container py-4">
<span class="badge rounded-pill bg-white bg-opacity-10 text-white border border-white border-opacity-25 mb-3">Scroll spy</span>
<h1 class="display-4 fw-bolder mb-3">Sticky slider navigation</h1>
<p class="fs-5 mx-auto mb-0 opacity-75" style="max-width:34rem">Sliding content with a tab bar that sticks to the top and follows you down the page.</p>
</div>
</header>
<nav class="ssn-bar" aria-label="Page sections" id="ssnBar">
<div class="container">
<div class="ssn-mask"><ul class="nav ssn-nav position-relative flex-nowrap" id="ssnNav">
<li class="ssn-slider" id="ssnSlider" aria-hidden="true"></li>
<li class="nav-item"><a class="nav-link ssn-link active" href="#ssn-overview" aria-current="true">Overview</a></li><li class="nav-item"><a class="nav-link ssn-link" href="#ssn-features">Features</a></li><li class="nav-item"><a class="nav-link ssn-link" href="#ssn-pricing">Pricing</a></li><li class="nav-item"><a class="nav-link ssn-link" href="#ssn-faq">FAQ</a></li><li class="nav-item"><a class="nav-link ssn-link" href="#ssn-contact">Contact</a></li>
</ul></div>
</div>
</nav>
<main>
<section id="ssn-overview" class="ssn-section"><div class="container" style="max-width:820px"><div class="mb-4"><span class="wdw-eyebrow">Overview</span><h2 class="wdw-heading display-6 mt-1 mb-2">Everything in one scroll</h2><p class="fs-5 wdw-muted mb-0" style="max-width:36rem">A single page where each section has its own tab. Scroll and the pill follows you; click a tab and the page glides to it.</p></div><div class="row g-3"><div class="col-4"><div class="wdw-card-sm p-3 text-center"><div class="h3 fw-bolder text-primary mb-0">5</div><div class="small wdw-muted">Sections</div></div></div><div class="col-4"><div class="wdw-card-sm p-3 text-center"><div class="h3 fw-bolder text-primary mb-0">1</div><div class="small wdw-muted">Sticky bar</div></div></div><div class="col-4"><div class="wdw-card-sm p-3 text-center"><div class="h3 fw-bolder text-primary mb-0">0</div><div class="small wdw-muted">Extra libraries</div></div></div></div></div></section>
<section id="ssn-features" class="ssn-section"><div class="container" style="max-width:820px"><div class="mb-4"><span class="wdw-eyebrow">Features</span><h2 class="wdw-heading display-6 mt-1 mb-2">Built for real pages</h2><p class="fs-5 wdw-muted mb-0" style="max-width:36rem">Sticky positioning, scroll spy and a sliding indicator, in a handful of lines.</p></div><div class="row g-3"><div class="col-md-4"><div class="wdw-card-sm p-4 h-100"><span class="wdw-icon mb-3"><svg width="22" height="22" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="1.85" stroke-linecap="round" stroke-linejoin="round" aria-hidden="true"><path d="M12 3v18M5 10l7-7 7 7"/></svg></span><h3 class="h6 mb-1">Sticky positioning</h3><p class="small wdw-muted mb-0">The bar pins to the top of the viewport the moment you scroll past the hero.</p></div></div><div class="col-md-4"><div class="wdw-card-sm p-4 h-100"><span class="wdw-icon mb-3"><svg width="22" height="22" 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="9"/><path d="M12 7v5l3 2"/></svg></span><h3 class="h6 mb-1">Live scroll spy</h3><p class="small wdw-muted mb-0">Bootstrap ScrollSpy marks the section in view and keeps the tab in sync.</p></div></div><div class="col-md-4"><div class="wdw-card-sm p-4 h-100"><span class="wdw-icon mb-3"><svg width="22" height="22" 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 12h16M14 6l6 6-6 6"/></svg></span><h3 class="h6 mb-1">Sliding indicator</h3><p class="small wdw-muted mb-0">A pill glides between tabs, so you always see where you are on the page.</p></div></div></div></div></section>
<section id="ssn-pricing" class="ssn-section"><div class="container" style="max-width:820px"><div class="mb-4"><span class="wdw-eyebrow">Pricing</span><h2 class="wdw-heading display-6 mt-1 mb-2">Simple, honest plans</h2><p class="fs-5 wdw-muted mb-0" style="max-width:36rem">Start free, upgrade when you grow. No setup fees and no surprises on the invoice.</p></div><div class="row g-3"><div class="col-md-4"><div class="wdw-card-sm p-4 h-100 d-flex flex-column"><h3 class="h6 mb-1">Starter</h3><p class="small wdw-muted">For side projects</p><div class="mb-3"><span class="display-6 fw-bolder text-body-emphasis">$0</span><span class="wdw-muted"> /mo</span></div><ul class="list-unstyled small mb-4"><li class="d-flex gap-2 mb-2"><svg width="18" height="18" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2.2" stroke-linecap="round" stroke-linejoin="round" class="text-primary flex-shrink-0 mt-1" aria-hidden="true"><path d="M5 12l5 5 9-10"/></svg>1 project</li><li class="d-flex gap-2 mb-2"><svg width="18" height="18" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2.2" stroke-linecap="round" stroke-linejoin="round" class="text-primary flex-shrink-0 mt-1" aria-hidden="true"><path d="M5 12l5 5 9-10"/></svg>Community support</li></ul><button type="button" class="btn btn-outline-primary rounded-pill mt-auto">Choose Starter</button></div></div><div class="col-md-4"><div class="wdw-card-sm p-4 h-100 d-flex flex-column border-primary border-2"><h3 class="h6 mb-1">Pro <span class="badge rounded-pill bg-primary-subtle text-primary-emphasis ms-1">Popular</span></h3><p class="small wdw-muted">For growing teams</p><div class="mb-3"><span class="display-6 fw-bolder text-body-emphasis">$19</span><span class="wdw-muted"> /mo</span></div><ul class="list-unstyled small mb-4"><li class="d-flex gap-2 mb-2"><svg width="18" height="18" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2.2" stroke-linecap="round" stroke-linejoin="round" class="text-primary flex-shrink-0 mt-1" aria-hidden="true"><path d="M5 12l5 5 9-10"/></svg>Unlimited projects</li><li class="d-flex gap-2 mb-2"><svg width="18" height="18" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2.2" stroke-linecap="round" stroke-linejoin="round" class="text-primary flex-shrink-0 mt-1" aria-hidden="true"><path d="M5 12l5 5 9-10"/></svg>Priority support</li><li class="d-flex gap-2 mb-2"><svg width="18" height="18" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2.2" stroke-linecap="round" stroke-linejoin="round" class="text-primary flex-shrink-0 mt-1" aria-hidden="true"><path d="M5 12l5 5 9-10"/></svg>Custom domains</li></ul><button type="button" class="btn btn-primary rounded-pill mt-auto">Choose Pro</button></div></div><div class="col-md-4"><div class="wdw-card-sm p-4 h-100 d-flex flex-column"><h3 class="h6 mb-1">Scale</h3><p class="small wdw-muted">For busy products</p><div class="mb-3"><span class="display-6 fw-bolder text-body-emphasis">$49</span><span class="wdw-muted"> /mo</span></div><ul class="list-unstyled small mb-4"><li class="d-flex gap-2 mb-2"><svg width="18" height="18" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2.2" stroke-linecap="round" stroke-linejoin="round" class="text-primary flex-shrink-0 mt-1" aria-hidden="true"><path d="M5 12l5 5 9-10"/></svg>Everything in Pro</li><li class="d-flex gap-2 mb-2"><svg width="18" height="18" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2.2" stroke-linecap="round" stroke-linejoin="round" class="text-primary flex-shrink-0 mt-1" aria-hidden="true"><path d="M5 12l5 5 9-10"/></svg>SSO and audit logs</li><li class="d-flex gap-2 mb-2"><svg width="18" height="18" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2.2" stroke-linecap="round" stroke-linejoin="round" class="text-primary flex-shrink-0 mt-1" aria-hidden="true"><path d="M5 12l5 5 9-10"/></svg>Dedicated manager</li></ul><button type="button" class="btn btn-outline-primary rounded-pill mt-auto">Choose Scale</button></div></div></div></div></section>
<section id="ssn-faq" class="ssn-section"><div class="container" style="max-width:820px"><div class="mb-4"><span class="wdw-eyebrow">FAQ</span><h2 class="wdw-heading display-6 mt-1 mb-2">Questions answered</h2><p class="fs-5 wdw-muted mb-0" style="max-width:36rem">Quick answers to the things people ask before they ship.</p></div><div class="accordion wdw-card-sm overflow-hidden" id="ssnFaq"><div class="accordion-item"><h3 class="accordion-header"><button class="accordion-button" type="button" data-bs-toggle="collapse" data-bs-target="#ssnQ0" aria-expanded="true" aria-controls="ssnQ0">Do I need a plugin?</button></h3><div id="ssnQ0" class="accordion-collapse collapse show" data-bs-parent="#ssnFaq"><div class="accordion-body wdw-muted">No. The component uses Bootstrap ScrollSpy and a few lines of vanilla JavaScript.</div></div></div><div class="accordion-item"><h3 class="accordion-header"><button class="accordion-button collapsed" type="button" data-bs-toggle="collapse" data-bs-target="#ssnQ1" aria-expanded="false" aria-controls="ssnQ1">Can I change the sections?</button></h3><div id="ssnQ1" class="accordion-collapse collapse" data-bs-parent="#ssnFaq"><div class="accordion-body wdw-muted">Yes. Add a link in the nav and a section with a matching id; the spy picks it up.</div></div></div><div class="accordion-item"><h3 class="accordion-header"><button class="accordion-button collapsed" type="button" data-bs-toggle="collapse" data-bs-target="#ssnQ2" aria-expanded="false" aria-controls="ssnQ2">Does it work on phones?</button></h3><div id="ssnQ2" class="accordion-collapse collapse" data-bs-parent="#ssnFaq"><div class="accordion-body wdw-muted">The tab bar scrolls sideways on narrow screens and keeps the active tab in view.</div></div></div></div></div></section>
<section id="ssn-contact" class="ssn-section"><div class="container" style="max-width:820px"><div class="mb-4"><span class="wdw-eyebrow">Contact</span><h2 class="wdw-heading display-6 mt-1 mb-2">Say hello</h2><p class="fs-5 wdw-muted mb-0" style="max-width:36rem">Tell us what you are building and we will point you to the right starting place.</p></div>
<form class="wdw-card p-4" onsubmit="return false"><div class="row g-3"><div class="col-md-6"><label class="form-label small fw-semibold" for="ssnName">Name</label><input class="form-control" id="ssnName" autocomplete="name"></div><div class="col-md-6"><label class="form-label small fw-semibold" for="ssnMail">Email</label><input type="email" class="form-control" id="ssnMail" autocomplete="email"></div><div class="col-12"><label class="form-label small fw-semibold" for="ssnMsg">Message</label><textarea class="form-control ssn-msg" id="ssnMsg" rows="3"></textarea></div><div class="col-12"><button type="submit" class="btn btn-primary rounded-pill px-4">Send message</button></div></div></form>
</div></section>
</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 */
.ssn { background: var(--wdw-stage); }
.ssn-hero { min-height: 300px; }
.ssn-bar { position: sticky; top: 0; z-index: 10; background: color-mix(in srgb, var(--bs-body-bg) 90%, transparent); backdrop-filter: blur(12px); -webkit-backdrop-filter: blur(12px); border-bottom: 1px solid var(--bs-border-color-translucent); transition: box-shadow .2s; }
.ssn-bar.is-stuck { box-shadow: var(--wdw-shadow-sm); }
.ssn-nav { overflow-x: auto; scrollbar-width: none; padding-block: .5rem; }
.ssn-nav::-webkit-scrollbar { display: none; }
.ssn-nav .nav-item { flex: 1 1 0; min-width: 5.5rem; position: relative; z-index: 1; }
.ssn-link { display: flex; align-items: center; justify-content: center; font-weight: 600; font-size: .9rem; white-space: nowrap; min-height: 44px; border-radius: 50rem; text-decoration: none; padding-inline: .75rem; }
.ssn-link.active { color: var(--bs-primary-text-emphasis); }
.ssn-slider { position: absolute; top: .5rem; left: 0; height: 44px; width: 0; border-radius: 50rem; background: var(--bs-primary-bg-subtle); border: 1px solid var(--bs-primary-border-subtle); transition: transform .3s cubic-bezier(.4,0,.2,1), width .3s cubic-bezier(.4,0,.2,1); list-style: none; z-index: 0; }
@media (max-width: 575.98px) { .ssn-mask { -webkit-mask-image: linear-gradient(90deg, #000 85%, transparent); mask-image: linear-gradient(90deg, #000 85%, transparent); } .ssn-nav { padding-right: 1.5rem; } }
.ssn-section { padding-block: 3.5rem; scroll-margin-top: 64px; }
.ssn-section:nth-child(even) { background: var(--bs-body-bg); }
.ssn-msg { min-height: 0; height: auto; }
@media (prefers-reduced-motion: reduce) { .ssn-slider { transition: none; } }
function initStickySliderNav() {
const bar = document.getElementById('ssnBar');
const nav = document.getElementById('ssnNav');
const slider = document.getElementById('ssnSlider');
if (!bar || !nav || !slider) return;
const links = [...nav.querySelectorAll('.ssn-link')];
const reduce = window.matchMedia('(prefers-reduced-motion: reduce)').matches;
const moveSlider = (link) => {
const item = link.parentElement;
slider.style.width = item.offsetWidth + 'px';
slider.style.transform = 'translateX(' + item.offsetLeft + 'px)';
};
const sync = () => {
const active = nav.querySelector('.ssn-link.active') || links[0];
links.forEach((l) => {
if (l === active) l.setAttribute('aria-current', 'true'); else l.removeAttribute('aria-current');
});
if (!nav.querySelector('.ssn-link.active')) active.classList.add('active');
moveSlider(active);
if (nav.scrollWidth > nav.clientWidth) nav.scrollTo({ left: active.parentElement.offsetLeft - 16, behavior: reduce ? 'auto' : 'smooth' });
};
new bootstrap.ScrollSpy(document.body, { target: '#ssnNav', rootMargin: '-80px 0px -55%', smoothScroll: false });
document.addEventListener('activate.bs.scrollspy', sync);
links.forEach((l) => l.addEventListener('click', (e) => {
e.preventDefault();
document.querySelector(l.getAttribute('href')).scrollIntoView({ behavior: reduce ? 'auto' : 'smooth', block: 'start' });
}));
window.addEventListener('scroll', () => bar.classList.toggle('is-stuck', bar.getBoundingClientRect().top <= 0), { passive: true });
window.addEventListener('resize', sync);
sync();
}
initStickySliderNav();
Built on Bootstrap 5.3.8 with plain JavaScript — no jQuery. Supports light and dark mode via data-bs-theme.