Scrollable Tab Bar
A tab bar with more tabs than fit: edge fades hint at hidden tabs, arrows scroll, and the chosen tab scrolls into view.
AI prompt
Clean UI mockup of a horizontal scrollable tab bar with ten tabs, Overview, Design, Motion, Typography, Colour, Layout, Accessibility, Code, Prompts and Examples, the tab Typography selected with a dark underline, a soft white fade at the right edge where Examples is cut off and a small round arrow button at the right, content area below with a short paragraph, light theme, flat modern style. Negative: heavy shadows, clutter, text errors, device frames. Reduced motion: static mockup.About this pattern
Definition
When there are more tabs than fit, a scrollable tab bar keeps them on one line instead of wrapping or hiding them. Fades at the edges show that more tabs exist, arrow buttons scroll for mouse users, and the selected tab is scrolled into view so it never hides off screen.
Purpose & UX principles
- Use overflow-x: auto with hidden scrollbars but keep scrolling via touch, wheel and arrows.
- Show an edge fade or arrow only on the side where more tabs exist.
- Scroll the selected tab into view when it changes, also from the keyboard.
- Follow the tabs pattern: role tablist, arrow keys to move, Home and End.
Interaction states
- Ten tabs, arrow buttons and keyboard control.
Motion specification
- Scrolling is smooth over about 250ms.
- Reduced motion: scrolling jumps instantly.
Responsive behaviour
- Put the most used tabs first.
- If there are more than about eight tabs, consider a menu instead.
Code
<div class="bx"><div class="tw" id="tw"><button class="ar l" id="al" type="button" aria-label="Scroll tabs left" hidden>‹</button><div class="tl" id="tl" role="tablist" aria-label="Sections"></div><button class="ar r" id="ar" type="button" aria-label="Scroll tabs right">›</button></div><div class="pn" id="pn" role="tabpanel" tabindex="0"></div></div>:root{--bg:#F1F1EF;--surface:#fff;--surface-2:#F7F7F5;--line:#E0E0DC;--text:#171717;--muted:#6f6f6f;--accent:#171717;--accent-ink:#fff;--danger:#d92d20}
*{box-sizing:border-box;margin:0}
button{font:inherit;color:inherit;background:none;border:0;padding:0;cursor:pointer}a{color:inherit;text-decoration:none}ul,ol,p,h4{margin:0;padding:0}.sr-only{position:absolute;width:1px;height:1px;overflow:hidden;clip:rect(0 0 0 0);white-space:nowrap}
.pre{display:flex;gap:5px;flex-wrap:wrap}.pre button{height:28px;padding:0 11px;border-radius:99px;border:1px solid var(--line);background:var(--surface);font-size:11px;cursor:pointer}
.pre button[aria-pressed=true]{background:var(--accent);color:var(--accent-ink);border-color:var(--accent)}
.bx{width:min(330px,100%);display:grid;gap:9px}.rw{display:grid;gap:3px;font-size:11.5px;color:var(--muted)}.rw b{color:var(--text);font-weight:600}input[type=range]{width:100%;accent-color:#171717}
.out{font-size:12px;color:var(--muted);line-height:1.4}.out b{color:var(--text)}
button:focus-visible,input:focus-visible{outline:2px solid var(--accent);outline-offset:2px}
.tw{position:relative;border-bottom:1px solid var(--line);min-width:0}.tl{min-width:0}.tl{display:flex;gap:2px;overflow-x:auto;scrollbar-width:none;scroll-behavior:smooth}.tl::-webkit-scrollbar{display:none}.tl button{flex:none;padding:9px 12px;font-size:12.5px;color:var(--muted);border-bottom:2px solid transparent;margin-bottom:-1px}.tl button[aria-selected=true]{color:var(--text);font-weight:600;border-color:#171717}.ar{position:absolute;top:2px;width:28px;height:28px;border-radius:50%;background:#fff;border:1px solid var(--line);box-shadow:0 2px 6px rgba(0,0,0,.12);font-size:16px;line-height:1;z-index:2}.ar.l{left:0}.ar.r{right:0}.tw.fl::before,.tw.fr::after{content:"";position:absolute;top:0;bottom:1px;width:36px;pointer-events:none;z-index:1}.tw.fl::before{left:0;background:linear-gradient(90deg,var(--pv),transparent)}.tw.fr::after{right:0;background:linear-gradient(270deg,var(--pv),transparent)}.pn{padding:12px 4px;font-size:12.5px;line-height:1.55;min-height:70px}@media (prefers-reduced-motion:reduce){.tl{scroll-behavior:auto}}
@media (prefers-reduced-motion:reduce){*{transition:none!important;animation:none!important}}const N=['Overview','Design','Motion','Typography','Colour','Layout','Accessibility','Code','Prompts','Examples'],tl=document.getElementById('tl'),tw=document.getElementById('tw'),pn=document.getElementById('pn'),al=document.getElementById('al'),ar=document.getElementById('ar');let cur=3;
tl.innerHTML=N.map((n,i)=>'<button type="button" role="tab" id="t'+i+'" aria-selected="'+(i===cur)+'" tabindex="'+(i===cur?0:-1)+'" aria-controls="pn">'+n+'</button>').join('');const tabs=[...tl.children];
function edges(){const l=tl.scrollLeft>2,r=tl.scrollLeft+tl.clientWidth<tl.scrollWidth-2;tw.classList.toggle('fl',l);tw.classList.toggle('fr',r);al.hidden=!l;ar.hidden=!r;}
function sel(i,f){cur=i;tabs.forEach((t,k)=>{t.setAttribute('aria-selected',k===i);t.tabIndex=k===i?0:-1;});pn.setAttribute('aria-labelledby','t'+i);pn.textContent=N[i]+': a short section about '+N[i].toLowerCase()+' with the details people need.';const t=tabs[i];tl.scrollTo({left:t.offsetLeft-tl.clientWidth/2+t.offsetWidth/2,behavior:matchMedia('(prefers-reduced-motion:reduce)').matches?'auto':'smooth'});if(f)t.focus();}
tabs.forEach((t,i)=>t.addEventListener('click',()=>sel(i,false)));tl.addEventListener('keydown',e=>{let i=cur;if(e.key==='ArrowRight')i=(cur+1)%N.length;else if(e.key==='ArrowLeft')i=(cur-1+N.length)%N.length;else if(e.key==='Home')i=0;else if(e.key==='End')i=N.length-1;else return;e.preventDefault();sel(i,true);});
al.addEventListener('click',()=>tl.scrollBy({left:-140}));ar.addEventListener('click',()=>tl.scrollBy({left:140}));tl.addEventListener('scroll',edges);new ResizeObserver(edges).observe(tl);sel(cur,false);setTimeout(edges,350);One complete HTML file. Save it and open it in a browser.
<!doctype html>
<html lang="en"><head><meta charset="utf-8"><meta name="viewport" content="width=device-width,initial-scale=1"><title>Scrollable Tab Bar — demo</title>
<style>
:root{--bg:#F1F1EF;--surface:#fff;--surface-2:#F7F7F5;--line:#E0E0DC;--text:#171717;--muted:#6f6f6f;--accent:#171717;--accent-ink:#fff;--danger:#d92d20}
*{box-sizing:border-box;margin:0}
html,body{height:100%}body{background:var(--bg);color:var(--text);font:15px/1.5 -apple-system,BlinkMacSystemFont,'Segoe UI',Inter,Roboto,sans-serif;-webkit-font-smoothing:antialiased}.stage{min-height:100%;display:grid;place-items:center;padding:24px}button,input,select,textarea{font-family:inherit}@media (prefers-reduced-motion:reduce){html{scroll-behavior:auto}}
button{font:inherit;color:inherit;background:none;border:0;padding:0;cursor:pointer}a{color:inherit;text-decoration:none}ul,ol,p,h4{margin:0;padding:0}.sr-only{position:absolute;width:1px;height:1px;overflow:hidden;clip:rect(0 0 0 0);white-space:nowrap}
.pre{display:flex;gap:5px;flex-wrap:wrap}.pre button{height:28px;padding:0 11px;border-radius:99px;border:1px solid var(--line);background:var(--surface);font-size:11px;cursor:pointer}
.pre button[aria-pressed=true]{background:var(--accent);color:var(--accent-ink);border-color:var(--accent)}
.bx{width:min(330px,100%);display:grid;gap:9px}.rw{display:grid;gap:3px;font-size:11.5px;color:var(--muted)}.rw b{color:var(--text);font-weight:600}input[type=range]{width:100%;accent-color:#171717}
.out{font-size:12px;color:var(--muted);line-height:1.4}.out b{color:var(--text)}
button:focus-visible,input:focus-visible{outline:2px solid var(--accent);outline-offset:2px}
.tw{position:relative;border-bottom:1px solid var(--line);min-width:0}.tl{min-width:0}.tl{display:flex;gap:2px;overflow-x:auto;scrollbar-width:none;scroll-behavior:smooth}.tl::-webkit-scrollbar{display:none}.tl button{flex:none;padding:9px 12px;font-size:12.5px;color:var(--muted);border-bottom:2px solid transparent;margin-bottom:-1px}.tl button[aria-selected=true]{color:var(--text);font-weight:600;border-color:#171717}.ar{position:absolute;top:2px;width:28px;height:28px;border-radius:50%;background:#fff;border:1px solid var(--line);box-shadow:0 2px 6px rgba(0,0,0,.12);font-size:16px;line-height:1;z-index:2}.ar.l{left:0}.ar.r{right:0}.tw.fl::before,.tw.fr::after{content:"";position:absolute;top:0;bottom:1px;width:36px;pointer-events:none;z-index:1}.tw.fl::before{left:0;background:linear-gradient(90deg,var(--pv),transparent)}.tw.fr::after{right:0;background:linear-gradient(270deg,var(--pv),transparent)}.pn{padding:12px 4px;font-size:12.5px;line-height:1.55;min-height:70px}@media (prefers-reduced-motion:reduce){.tl{scroll-behavior:auto}}
@media (prefers-reduced-motion:reduce){*{transition:none!important;animation:none!important}}
</style></head>
<body><div class="stage">
<div class="bx"><div class="tw" id="tw"><button class="ar l" id="al" type="button" aria-label="Scroll tabs left" hidden>‹</button><div class="tl" id="tl" role="tablist" aria-label="Sections"></div><button class="ar r" id="ar" type="button" aria-label="Scroll tabs right">›</button></div><div class="pn" id="pn" role="tabpanel" tabindex="0"></div></div>
</div>
<script>
const N=['Overview','Design','Motion','Typography','Colour','Layout','Accessibility','Code','Prompts','Examples'],tl=document.getElementById('tl'),tw=document.getElementById('tw'),pn=document.getElementById('pn'),al=document.getElementById('al'),ar=document.getElementById('ar');let cur=3;
tl.innerHTML=N.map((n,i)=>'<button type="button" role="tab" id="t'+i+'" aria-selected="'+(i===cur)+'" tabindex="'+(i===cur?0:-1)+'" aria-controls="pn">'+n+'</button>').join('');const tabs=[...tl.children];
function edges(){const l=tl.scrollLeft>2,r=tl.scrollLeft+tl.clientWidth<tl.scrollWidth-2;tw.classList.toggle('fl',l);tw.classList.toggle('fr',r);al.hidden=!l;ar.hidden=!r;}
function sel(i,f){cur=i;tabs.forEach((t,k)=>{t.setAttribute('aria-selected',k===i);t.tabIndex=k===i?0:-1;});pn.setAttribute('aria-labelledby','t'+i);pn.textContent=N[i]+': a short section about '+N[i].toLowerCase()+' with the details people need.';const t=tabs[i];tl.scrollTo({left:t.offsetLeft-tl.clientWidth/2+t.offsetWidth/2,behavior:matchMedia('(prefers-reduced-motion:reduce)').matches?'auto':'smooth'});if(f)t.focus();}
tabs.forEach((t,i)=>t.addEventListener('click',()=>sel(i,false)));tl.addEventListener('keydown',e=>{let i=cur;if(e.key==='ArrowRight')i=(cur+1)%N.length;else if(e.key==='ArrowLeft')i=(cur-1+N.length)%N.length;else if(e.key==='Home')i=0;else if(e.key==='End')i=N.length-1;else return;e.preventDefault();sel(i,true);});
al.addEventListener('click',()=>tl.scrollBy({left:-140}));ar.addEventListener('click',()=>tl.scrollBy({left:140}));tl.addEventListener('scroll',edges);new ResizeObserver(edges).observe(tl);sel(cur,false);setTimeout(edges,350);
</script>
</body></html>