Sliding tab indicator
Indicador de pestaña deslizante · Sliding tab indicator · Animated tabs · Segmented control · Sottolineatura che scivola
When you switch tabs, the pill or underline marking the active one glides to the new item, stretching and shrinking along the way. It shows at once where you came from and where you are going.
- Era
- 2014 – today
- Use
- Mainstream
Live demo
View code
<main>
<div class="seg" role="tablist"><i class="pill"></i><button class="on">Giorno</button><button>Settimana</button><button>Mese</button></div>
<div class="under" role="tablist"><i class="ln"></i><button class="on">Tutte</button><button>Non lette</button><button>Archivio</button><button>Spam</button></div>
<section class="panel"><b class="num">12</b><span>attività in programma</span></section>
</main>
<script>
const groups=[...document.querySelectorAll('[role=tablist]')],num=document.querySelector('.num'),vals=['12','47','186'],panel=document.querySelector('.panel');
const sel=(g,i)=>{const bs=[...g.querySelectorAll('button')],b=bs[i],ind=g.querySelector('i'),prev=bs.findIndex(x=>x.classList.contains('on'));
bs.forEach(x=>x.classList.toggle('on',x===b));ind.style.setProperty('--x',b.offsetLeft+'px');ind.style.setProperty('--w',b.offsetWidth+'px');
if(g.classList.contains('seg')&&prev!==i){panel.style.setProperty('--d',i>prev?1:-1);panel.classList.remove('in');void panel.offsetWidth;panel.classList.add('in');num.textContent=vals[i]}};
groups.forEach(g=>{[...g.querySelectorAll('button')].forEach((b,i)=>b.onclick=()=>{auto=false;sel(g,i)});sel(g,0)});
document.fonts&&document.fonts.ready.then(()=>groups.forEach(g=>sel(g,[...g.querySelectorAll('button')].findIndex(b=>b.classList.contains('on')))));
let auto=true,k=0;const seq=[1,2,0,2,1,0];
if(matchMedia('(prefers-reduced-motion: no-preference)').matches)setInterval(()=>{if(!auto)return;const n=seq[k++%seq.length];sel(groups[0],n);sel(groups[1],(k*3)%4)},1500);
</script> body{margin:0;height:100vh;display:grid;place-items:center;background:#EEF0F6;font-family:Manrope,sans-serif;color:#15172B}
main{width:380px;max-width:92vw;display:grid;gap:16px}
.seg,.under{position:relative;display:flex}
.seg{background:#fff;border-radius:14px;padding:5px;box-shadow:0 8px 20px -14px #15172B66}
button{all:unset;position:relative;z-index:1;flex:1;text-align:center;padding:10px 0;font-size:14px;font-weight:700;color:#8A8FA8;cursor:pointer;transition:color .3s}
.seg .on{color:#fff}
.under{border-bottom:1px solid #15172B1a}
.under button{flex:none;padding:8px 12px;font-weight:500}
.under .on{color:#15172B;font-weight:700}
i{--x:0px;--w:0px;position:absolute;left:0;width:var(--w);transform:translateX(var(--x))}
.pill{top:5px;bottom:5px;border-radius:10px;background:linear-gradient(135deg,#5B5BF0,#7d6bff);box-shadow:0 6px 14px -6px #5B5BF0}
.ln{bottom:-1px;height:3px;border-radius:3px;background:#FF8FAB}
.panel{background:#fff;border-radius:16px;padding:16px 18px;display:flex;align-items:baseline;gap:10px;overflow:hidden}
.num{font-size:40px;font-weight:800;color:#5B5BF0;display:inline-block}
.panel span{color:#8A8FA8;font-size:14px}
@media (prefers-reduced-motion:no-preference){
.pill{transition:transform .42s cubic-bezier(.65,0,.35,1),width .42s cubic-bezier(.65,0,.35,1)}
.ln{transition:transform .45s cubic-bezier(.65,0,.35,1),width .25s cubic-bezier(.3,0,.2,1)}
.panel.in .num,.panel.in span{animation:pin .45s cubic-bezier(.2,.8,.2,1) both}
.panel.in span{animation-delay:.05s}
@keyframes pin{from{opacity:0;transform:translateX(calc(var(--d)*30px))}}
} Characteristics
- One shared indicator moving between items
- Width adapting to the destination label
- Inchworm stretch before reaching the target
- Panel content entering from the right direction
- Text colour inverting over the pill
Palette
Click a swatch to copy it
Typography
Headings · Manrope Sliding tab indicator
Body · Manrope When you switch tabs, the pill or underline marking the active one glides to the new item, stretching and shrinking along the way. It shows at once where you came from and where you are going.
Motion
- Easing
cubic-bezier(0.65, 0, 0.35, 1) o spring- Typical duration
- 250–400 ms
- Techniques
- variabili CSS per posizione e larghezza misurate, Framer Motion layoutId, anchor positioning CSS, View Transitions API, transform translateX e scaleX
Accessibility (reduced motion)
The indicator jumps straight under the new tab; content swaps without sliding.
Prompt for your agent
Copy and paste into your prompt to have an agent or image generator reproduce this style.
For web pages and UI
Design the web page or interface in this style: Sliding tab indicator (Indicador de pestaña deslizante). When you switch tabs, the pill or underline marking the active one glides to the new item, stretching and shrinking along the way. It shows at once where you came from and where you are going. Characteristics: One shared indicator moving between items, Width adapting to the destination label, Inchworm stretch before reaching the target, Panel content entering from the right direction, Text colour inverting over the pill. Palette: #EEF0F6, #FFFFFF, #15172B, #5B5BF0, #FF8FAB, #8A8FA8. Typography: headings in Manrope, body text in Manrope (Google Fonts or equivalents). Mood: clean, rational, playful. Motion: easing cubic-bezier(0.65, 0, 0.35, 1) o spring, typical duration 250–400 ms; techniques: variabili CSS per posizione e larghezza misurate, Framer Motion layoutId, anchor positioning CSS, View Transitions API, transform translateX e scaleX. With prefers-reduced-motion: The indicator jumps straight under the new tab; content swaps without sliding. References: Tab di Material Design (2014), segmented control di iOS, Framer Motion layoutId, esempi di Radix Tabs.
Relations
References
- Tab di Material Design (2014)
- segmented control di iOS
- Framer Motion layoutId
- esempi di Radix Tabs