Bootstrap 5 Animated Menu with Sliding Indicator
A pill-shaped navigation bar with a highlight that slides to the active link, plus a content card that updates with each choice.
<section class="wdw-stage">
<div class="container" style="max-width:820px">
<div class="text-center mb-4">
<span class="wdw-eyebrow">Navigation</span>
<h2 class="wdw-heading display-6 mt-1 mb-2">Menu with a sliding indicator</h2>
<p class="wdw-muted mb-0">The highlight glides to whichever tab you pick, with arrow-key support.</p>
</div>
<div class="d-flex justify-content-center">
<div class="wdw-menu-wrap">
<div class="nav nav-pills wdw-menu flex-nowrap" role="tablist" aria-label="Primary" id="wdwMenu">
<span class="wdw-menu-pill" aria-hidden="true"></span>
<button type="button" class="nav-link active" role="tab" id="wdwTab-home" aria-controls="wdwMenuPanel" aria-selected="true" tabindex="0" data-title="Welcome home" data-text="A clear starting point: headline, primary action and the three things visitors look for first." data-icon="M4 10.5 12 4l8 6.5V20H4z">Home</button>
<button type="button" class="nav-link" role="tab" id="wdwTab-about" aria-controls="wdwMenuPanel" aria-selected="false" tabindex="-1" data-title="About the studio" data-text="Who we are, how we work and the principles behind every project we ship." data-icon="M12 12a4 4 0 1 0 0-8 4 4 0 0 0 0 8zM4 21a8 8 0 0 1 16 0">About</button>
<button type="button" class="nav-link" role="tab" id="wdwTab-testimonials" aria-controls="wdwMenuPanel" aria-selected="false" tabindex="-1" data-title="Kind words" data-text="Short, specific quotes from clients, each paired with the result they saw." data-icon="M4 5h16v11H9l-5 4z">Testimonials</button>
<button type="button" class="nav-link" role="tab" id="wdwTab-blog" aria-controls="wdwMenuPanel" aria-selected="false" tabindex="-1" data-title="Notes from the blog" data-text="Practical write-ups on design systems, front-end craft and shipping faster." data-icon="M5 4h14v16H5zM8 9h8M8 13h8M8 17h5">Blog</button>
<button type="button" class="nav-link" role="tab" id="wdwTab-contact" aria-controls="wdwMenuPanel" aria-selected="false" tabindex="-1" data-title="Let's talk" data-text="Tell us about your project and we will reply within one working day." data-icon="M3 6h18v12H3zM3 6l9 7 9-7">Contact</button>
</div>
</div>
</div>
<div class="wdw-card p-4 p-md-5 mt-4" role="tabpanel" id="wdwMenuPanel" aria-labelledby="wdwTab-home" tabindex="0">
<div class="d-flex gap-4 align-items-start">
<span class="wdw-icon" style="width:3.5rem;height:3.5rem">
<svg width="26" height="26" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="1.75" stroke-linecap="round" stroke-linejoin="round" aria-hidden="true"><path id="wdwMenuIcon" d="M4 10.5 12 4l8 6.5V20H4z"/></svg>
</span>
<div class="flex-grow-1">
<h3 class="h4 wdw-heading mb-2" id="wdwMenuTitle">Welcome home</h3>
<p class="wdw-muted mb-0" id="wdwMenuText">A clear starting point: headline, primary action and the three things visitors look for first.</p>
</div>
</div>
<div class="mt-4 d-grid gap-2" aria-hidden="true">
<div class="wdw-skel" style="width:100%"></div>
<div class="wdw-skel" style="width:86%"></div>
<div class="wdw-skel" style="width:64%"></div>
</div>
<div class="d-flex flex-wrap gap-2 mt-4">
<button type="button" class="btn btn-primary rounded-pill px-4">Explore</button>
<button type="button" class="btn btn-outline-secondary rounded-pill px-4">Learn more</button>
</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-wrap { max-width: 100%; position: relative; }
.wdw-menu { --bs-nav-link-padding-x: 1.375rem; position: relative; display: flex; padding: .375rem; gap: .125rem; background: var(--bs-body-bg); border: 1px solid var(--bs-border-color-translucent); border-radius: 50rem; box-shadow: var(--wdw-shadow); overflow-x: auto; scrollbar-width: none; }
.wdw-menu::-webkit-scrollbar { display: none; }
.wdw-menu.has-end { -webkit-mask-image: linear-gradient(to right, #000 calc(100% - 40px), transparent); mask-image: linear-gradient(to right, #000 calc(100% - 40px), transparent); }
.wdw-menu.has-start { -webkit-mask-image: linear-gradient(to left, #000 calc(100% - 40px), transparent); mask-image: linear-gradient(to left, #000 calc(100% - 40px), transparent); }
.wdw-menu.has-start.has-end { -webkit-mask-image: linear-gradient(to right, transparent, #000 40px, #000 calc(100% - 40px), transparent); mask-image: linear-gradient(to right, transparent, #000 40px, #000 calc(100% - 40px), transparent); }
.wdw-menu .nav-link { position: relative; z-index: 1; flex: none; min-height: 52px; border-radius: 50rem; font-weight: 600; font-size: 1rem; background: transparent; transition: color .25s; }
.wdw-menu .nav-link:hover { color: var(--bs-emphasis-color); }
.wdw-menu .nav-link.active, .wdw-menu .nav-link.active:hover { background: transparent; color: var(--bs-body-bg); }
.wdw-menu .nav-link:focus-visible { outline: 2px solid var(--bs-primary); outline-offset: 2px; box-shadow: none; }
.wdw-menu-pill { position: absolute; z-index: 0; top: .375rem; left: 0; height: 52px; width: 0; border-radius: 50rem; background: var(--bs-primary); box-shadow: 0 6px 16px -4px rgba(var(--bs-primary-rgb), .55); transition: transform .35s cubic-bezier(.3,1.2,.4,1), width .35s cubic-bezier(.3,1.2,.4,1); }
.wdw-menu-pill.is-init { transition: none; }
.wdw-skel { height: .75rem; border-radius: 50rem; background: var(--bs-secondary-bg); }
@media (max-width: 575.98px) { .wdw-menu { --bs-nav-link-padding-x: 1rem; } .wdw-menu .nav-link { font-size: .9375rem; } }
@media (prefers-reduced-motion: reduce) { .wdw-menu-pill { transition: none; } }
function initMenuIndicator() {
var menu = document.getElementById('wdwMenu');
if (!menu) return;
var pill = menu.querySelector('.wdw-menu-pill');
var tabs = Array.prototype.slice.call(menu.querySelectorAll('[role="tab"]'));
var panel = document.getElementById('wdwMenuPanel');
var title = document.getElementById('wdwMenuTitle');
var text = document.getElementById('wdwMenuText');
var icon = document.getElementById('wdwMenuIcon');
function current() { return menu.querySelector('[aria-selected="true"]'); }
function moveTo(tab, instant) {
if (instant) pill.classList.add('is-init');
pill.style.width = tab.offsetWidth + 'px';
pill.style.transform = 'translateX(' + tab.offsetLeft + 'px)';
if (instant) { pill.offsetWidth; pill.classList.remove('is-init'); }
}
function updateFade() {
menu.classList.toggle('has-start', menu.scrollLeft > 4);
menu.classList.toggle('has-end', menu.scrollLeft + menu.clientWidth < menu.scrollWidth - 4);
}
function activate(tab) {
tabs.forEach(function (t) {
var on = t === tab;
t.classList.toggle('active', on);
t.setAttribute('aria-selected', on ? 'true' : 'false');
t.tabIndex = on ? 0 : -1;
});
moveTo(tab);
panel.setAttribute('aria-labelledby', tab.id);
title.textContent = tab.dataset.title;
text.textContent = tab.dataset.text;
icon.setAttribute('d', tab.dataset.icon);
tab.scrollIntoView({ block: 'nearest', inline: 'center' });
}
tabs.forEach(function (tab, i) {
tab.addEventListener('click', function () { activate(tab); });
tab.addEventListener('keydown', function (e) {
var next = null;
if (e.key === 'ArrowRight') next = i + 1;
else if (e.key === 'ArrowLeft') next = i - 1;
else if (e.key === 'Home') next = 0;
else if (e.key === 'End') next = tabs.length - 1;
if (next === null) return;
e.preventDefault();
var target = tabs[(next + tabs.length) % tabs.length];
target.focus();
activate(target);
});
});
function refresh() { moveTo(current(), true); updateFade(); }
menu.addEventListener('scroll', updateFade, { passive: true });
window.addEventListener('resize', refresh);
if (document.fonts && document.fonts.ready) document.fonts.ready.then(refresh);
refresh();
}
initMenuIndicator();
Built on Bootstrap 5.3.8 with plain JavaScript — no jQuery. Supports light and dark mode via data-bs-theme.