Glijdend menuvlak
A black block glides behind the menu item you point at or tab to and slides back to the active page when you leave; below it the same technique as a tab switcher with arrow keys.
How to use it
- Paste the HTML where the navigation & menus should appear.
- Add the CSS to your stylesheet. All classes are prefixed, so nothing clashes with your own styles.
- Add the JavaScript and call init() with the element that contains the HTML.
<!-- Glijdend menuvlak · © 2026 NedDev BV · NedDev Lab-licentie (gratis gebruik, niet doorverkopen) · neddev.com/nl/lab/gebruik/#licentie -->
<div class="jouw-container">
<div class="h4hn">
<nav class="h4hn__nav" aria-label="Voorbeeldmenu">
<span class="h4hn__ind" aria-hidden="true"></span>
<a class="h4hn__a" href="#diensten">Diensten</a>
<a class="h4hn__a" href="#werk" aria-current="page">Werk</a>
<a class="h4hn__a" href="#tarieven">Tarieven</a>
<a class="h4hn__a" href="#contact">Contact</a>
</nav>
<div class="h4hn__seg" role="tablist" aria-label="Soort klant">
<span class="h4hn__ind h4hn__ind--seg" aria-hidden="true"></span>
<button class="h4hn__tab" type="button" role="tab" aria-selected="true" data-uit="Offerte binnen twee werkdagen, bedragen inclusief btw.">Particulier</button>
<button class="h4hn__tab" type="button" role="tab" aria-selected="false" tabindex="-1" data-uit="Op rekening met 30 dagen betaaltermijn, bedragen exclusief btw.">Zakelijk</button>
<button class="h4hn__tab" type="button" role="tab" aria-selected="false" tabindex="-1" data-uit="Korting voor stichtingen en verenigingen met een KvK-inschrijving.">Vereniging</button>
</div>
<p class="h4hn__out" role="tabpanel" aria-live="polite">Offerte binnen twee werkdagen, bedragen inclusief btw.</p>
</div>
</div>/* Glijdend menuvlak · © 2026 NedDev BV · NedDev Lab-licentie (gratis gebruik, niet doorverkopen) · neddev.com/nl/lab/gebruik/#licentie */
.h4hn{position:absolute;inset:0;display:flex;flex-direction:column;align-items:center;justify-content:center;gap:16px;padding:0 14px;font-family:'Switzer',sans-serif;color:#0a0a0a}
.h4hn__nav,.h4hn__seg{position:relative;display:flex;padding:4px;background:#fff;border:1px solid rgba(10,10,10,.12);border-radius:4px}
.h4hn__ind{position:absolute;left:0;top:4px;bottom:4px;width:0;background:#0a0a0a;border-radius:3px;transform:translateX(0);pointer-events:none}
.h4hn__ind.is-anim{transition:transform .38s cubic-bezier(.3,.8,.2,1),width .38s cubic-bezier(.3,.8,.2,1)}
.h4hn__ind--seg{background:#F5480F}
.h4hn__a,.h4hn__tab{position:relative;z-index:1;display:flex;align-items:center;min-height:34px;padding:0 14px;font:500 14px 'Switzer',sans-serif;color:#0a0a0a;text-decoration:none;border:0;background:none;border-radius:3px;cursor:pointer;white-space:nowrap;transition:color .25s}
.h4hn__a.is-on,.h4hn__tab.is-on{color:#fff}
.h4hn__a[aria-current=page]{font-weight:600}
.h4hn__a:focus-visible,.h4hn__tab:focus-visible{outline:2px solid #F5480F;outline-offset:2px}
.h4hn__out{margin:0;min-height:2.8em;max-width:36ch;text-align:center;font-size:13px;line-height:1.4;color:rgba(10,10,10,.7)}
@media (max-width:380px){.h4hn__a,.h4hn__tab{padding:0 10px;font-size:13px}}
@media (prefers-reduced-motion:reduce){.h4hn__ind.is-anim,.h4hn__a,.h4hn__tab{transition:none}}// Glijdend menuvlak · © 2026 NedDev BV · NedDev Lab-licentie (gratis gebruik, niet doorverkopen) · neddev.com/nl/lab/gebruik/#licentie
// root = het element waarin de HTML staat
function init(root){
var w=root.querySelector('.h4hn');if(!w)return;
function slider(box,items,ind,getActive){
var hot=null;
function place(el,anim){
if(!el)return;
ind.classList.toggle('is-anim',!!anim);
ind.style.width=el.offsetWidth+'px';ind.style.transform='translateX('+el.offsetLeft+'px)';
items.forEach(function(it){it.classList.toggle('is-on',it===el);});
}
items.forEach(function(it){
it.addEventListener('pointerenter',function(){hot=it;place(it,true);});
it.addEventListener('focus',function(){hot=it;place(it,true);});
});
box.addEventListener('pointerleave',function(){hot=null;place(getActive(),true);});
box.addEventListener('focusout',function(e){if(!box.contains(e.relatedTarget)){hot=null;place(getActive(),true);}});
function reset(){place(hot||getActive(),false);}
reset();
if('ResizeObserver' in window)new ResizeObserver(reset).observe(box);
if(document.fonts&&document.fonts.ready)document.fonts.ready.then(reset);
return place;
}
var nav=w.querySelector('.h4hn__nav'),links=[].slice.call(nav.querySelectorAll('.h4hn__a'));
function activeLink(){return nav.querySelector('[aria-current=page]')||links[0];}
var placeNav=slider(nav,links,nav.querySelector('.h4hn__ind'),activeLink);
links.forEach(function(a){a.addEventListener('click',function(e){e.preventDefault();links.forEach(function(x){x.removeAttribute('aria-current');});a.setAttribute('aria-current','page');placeNav(a,true);});});
var seg=w.querySelector('.h4hn__seg'),tabs=[].slice.call(seg.querySelectorAll('.h4hn__tab')),out=w.querySelector('.h4hn__out');
function activeTab(){return seg.querySelector('[aria-selected=true]')||tabs[0];}
var placeSeg=slider(seg,tabs,seg.querySelector('.h4hn__ind'),activeTab);
function pick(t,focus){
tabs.forEach(function(x){var on=x===t;x.setAttribute('aria-selected',on?'true':'false');x.tabIndex=on?0:-1;});
out.textContent=t.getAttribute('data-uit');placeSeg(t,true);if(focus)t.focus();
}
tabs.forEach(function(t,i){
t.addEventListener('click',function(){pick(t,false);});
t.addEventListener('keydown',function(e){
var n=null;
if(e.key==='ArrowRight')n=tabs[(i+1)%tabs.length];else if(e.key==='ArrowLeft')n=tabs[(i-1+tabs.length)%tabs.length];
else if(e.key==='Home')n=tabs[0];else if(e.key==='End')n=tabs[tabs.length-1];
if(n){e.preventDefault();pick(n,true);}
});
});
}
init(document.querySelector('.jouw-container'));
More navigation & menus
Seen something you like?
Add it to your selection and send it over. We build your site around it, in your brand.
Get in touch →