Scroll
import { useId, useRef, useState } from 'react';
const ITEMS = [
{ label: 'I', title: 'On bread', body: 'Every street shall have one good bakery.' },
{ label: 'II', title: 'On rest', body: 'Sundays belong to long lunches and naps.' },
{ label: 'III', title: 'On music', body: 'The square shall have a piano, always tuned.' },
];
const css = `
@keyframes tabs-scroll-unroll { from { clip-path: inset(0 0 100% 0); } to { clip-path: inset(0 0 0 0); } }
@keyframes tabs-scroll-roll { from { transform: translateY(-96px); } to { transform: none; } }
.tabs-scroll { display: grid; justify-items: center; gap: 12px; width: 240px; }
.tabs-scroll__list { display: flex; gap: 6px; }
.tabs-scroll__tab { position: relative; padding: 0; border: 0; background: none; font: inherit; cursor: pointer; }
.tabs-scroll__tab:focus-visible { outline: 2px solid light-dark(#50535b, #c6c8cd); outline-offset: 3px; border-radius: 8px; }
.tabs-scroll__tab { width: 40px; height: 32px; border-radius: 16px; color: light-dark(#5f626a, #a7abb2); font-family: Georgia, 'Times New Roman', serif; font-size: 14px; box-shadow: inset 0 0 0 1px light-dark(#dbdde1, #2e3035); transition: background-color 0.2s, color 0.2s; }
.tabs-scroll__tab[aria-selected='true'] { background: light-dark(#373a40, #f1f2f3); color: light-dark(#fbfcfd, #121417); box-shadow: none; }
.tabs-scroll__stage { position: relative; width: 200px; }
.tabs-scroll__rod { position: relative; z-index: 1; height: 10px; margin: 0 -8px; border-radius: 5px; background: linear-gradient(light-dark(#5f626a, #a7abb2), light-dark(#cbced3, #393c41)); box-shadow: 0 3px 6px -2px light-dark(rgba(0, 0, 0, 0.15), rgba(0, 0, 0, 0.5)); }
.tabs-scroll__rod::before, .tabs-scroll__rod::after { content: ''; position: absolute; top: -2px; width: 8px; height: 14px; border-radius: 3px; background: light-dark(#50535b, #c6c8cd); }
.tabs-scroll__rod::before { left: -4px; }
.tabs-scroll__rod::after { right: -4px; }
.tabs-scroll__panel { display: grid; justify-items: center; gap: 6px; height: 96px; padding: 14px 16px; background: linear-gradient(90deg, light-dark(#ebedf0, #232529), light-dark(#f3f4f7, #1a1c1f) 15%, light-dark(#f3f4f7, #1a1c1f) 85%, light-dark(#ebedf0, #232529)); color: light-dark(#50535b, #c6c8cd); font-family: Georgia, 'Times New Roman', serif; font-size: 12.5px; font-style: italic; line-height: 1.45; text-align: center; }
.tabs-scroll__panel b { color: light-dark(#373a40, #f1f2f3); font-size: 15px; font-style: normal; font-weight: 400; letter-spacing: 0.04em; }
.tabs-scroll__roll { position: absolute; left: -8px; right: -8px; bottom: -5px; height: 10px; border-radius: 5px; background: linear-gradient(light-dark(#5f626a, #a7abb2), light-dark(#cbced3, #393c41)); box-shadow: 0 3px 6px -2px light-dark(rgba(0, 0, 0, 0.15), rgba(0, 0, 0, 0.5)); }
.tabs-scroll[data-armed] .tabs-scroll__panel { animation: tabs-scroll-unroll 0.7s cubic-bezier(0.4, 0, 0.3, 1) both; }
.tabs-scroll[data-armed] .tabs-scroll__roll { animation: tabs-scroll-roll 0.7s cubic-bezier(0.4, 0, 0.3, 1) both; }
.tabs-scroll[data-flip='b'] .tabs-scroll__roll { animation-name: tabs-scroll-roll-b; }
@keyframes tabs-scroll-roll-b { from { transform: translateY(-96px); } to { transform: none; } }
@media (prefers-reduced-motion: reduce) {
.tabs-scroll__panel, .tabs-scroll__roll { animation: none !important; }
}
`;
export function ScrollTabs() {
const id = useId();
const [state, setState] = useState({ sel: 0, prev: -1, flip: 0 });
const tabs = useRef<(HTMLButtonElement | null)[]>([]);
const { sel, prev, flip } = state;
const select = (i: number) => {
if (i !== sel) setState((s) => ({ sel: i, prev: s.sel, flip: s.flip + 1 }));
};
const onKeyDown = (e: React.KeyboardEvent) => {
const n = ITEMS.length;
const next = ({ ArrowRight: (sel + 1) % n, ArrowLeft: (sel + n - 1) % n, Home: 0, End: n - 1 } as Record<string, number>)[e.key];
if (next === undefined) return;
e.preventDefault();
select(next);
tabs.current[next]?.focus();
};
return (
<>
<style>
{css}
</style>
<div
className="tabs-scroll"
data-armed={flip ? '' : undefined}
data-flip={flip ? (flip % 2 ? 'a' : 'b') : undefined}
style={{ '--i': sel, '--p': prev < 0 ? sel : prev } as React.CSSProperties}
>
<div className="tabs-scroll__list" role="tablist" aria-label="Decrees" onKeyDown={onKeyDown}>
{ITEMS.map((t, i) => (
<button
key={t.label}
ref={(el) => {
tabs.current[i] = el;
}}
className="tabs-scroll__tab"
type="button"
role="tab"
id={`${id}-tab-${i}`}
aria-selected={sel === i}
aria-controls={`${id}-panel-${i}`}
tabIndex={sel === i ? 0 : -1}
onClick={() => select(i)}
>
{t.label}
</button>
))}
</div>
<div className="tabs-scroll__stage">
<div className="tabs-scroll__rod" aria-hidden="true" />
{ITEMS.map((t, i) => (
<div key={t.label} className="tabs-scroll__panel" role="tabpanel" id={`${id}-panel-${i}`} aria-labelledby={`${id}-tab-${i}`} hidden={sel !== i}>
<b>{t.title}</b>
{t.body}
</div>
))}
<span className="tabs-scroll__roll" aria-hidden="true" />
</div>
</div>
</>
);
}Markup where the component goes, CSS in your stylesheet, script before </body>. In Vue, Svelte or Angular, call initTabsScroll(el) on the mounted element instead.
<div class="tabs-scroll" style="--i:0;--p:0">
<div class="tabs-scroll__list" role="tablist" aria-label="Decrees">
<button class="tabs-scroll__tab" type="button" role="tab" id="tabs-scroll-tab-0" aria-selected="true" aria-controls="tabs-scroll-panel-0" tabindex="0">I</button>
<button class="tabs-scroll__tab" type="button" role="tab" id="tabs-scroll-tab-1" aria-selected="false" aria-controls="tabs-scroll-panel-1" tabindex="-1">II</button>
<button class="tabs-scroll__tab" type="button" role="tab" id="tabs-scroll-tab-2" aria-selected="false" aria-controls="tabs-scroll-panel-2" tabindex="-1">III</button>
</div>
<div class="tabs-scroll__stage">
<div class="tabs-scroll__rod" aria-hidden="true"></div>
<div class="tabs-scroll__panel" role="tabpanel" id="tabs-scroll-panel-0" aria-labelledby="tabs-scroll-tab-0"><b>On bread</b>Every street shall have one good bakery.</div>
<div class="tabs-scroll__panel" role="tabpanel" id="tabs-scroll-panel-1" aria-labelledby="tabs-scroll-tab-1" hidden=""><b>On rest</b>Sundays belong to long lunches and naps.</div>
<div class="tabs-scroll__panel" role="tabpanel" id="tabs-scroll-panel-2" aria-labelledby="tabs-scroll-tab-2" hidden=""><b>On music</b>The square shall have a piano, always tuned.</div>
<span class="tabs-scroll__roll" aria-hidden="true"></span>
</div>
</div>@keyframes tabs-scroll-unroll { from { clip-path: inset(0 0 100% 0); } to { clip-path: inset(0 0 0 0); } }
@keyframes tabs-scroll-roll { from { transform: translateY(-96px); } to { transform: none; } }
.tabs-scroll { display: grid; justify-items: center; gap: 12px; width: 240px; }
.tabs-scroll__list { display: flex; gap: 6px; }
.tabs-scroll__tab { position: relative; padding: 0; border: 0; background: none; font: inherit; cursor: pointer; }
.tabs-scroll__tab:focus-visible { outline: 2px solid light-dark(#50535b, #c6c8cd); outline-offset: 3px; border-radius: 8px; }
.tabs-scroll__tab { width: 40px; height: 32px; border-radius: 16px; color: light-dark(#5f626a, #a7abb2); font-family: Georgia, 'Times New Roman', serif; font-size: 14px; box-shadow: inset 0 0 0 1px light-dark(#dbdde1, #2e3035); transition: background-color 0.2s, color 0.2s; }
.tabs-scroll__tab[aria-selected='true'] { background: light-dark(#373a40, #f1f2f3); color: light-dark(#fbfcfd, #121417); box-shadow: none; }
.tabs-scroll__stage { position: relative; width: 200px; }
.tabs-scroll__rod { position: relative; z-index: 1; height: 10px; margin: 0 -8px; border-radius: 5px; background: linear-gradient(light-dark(#5f626a, #a7abb2), light-dark(#cbced3, #393c41)); box-shadow: 0 3px 6px -2px light-dark(rgba(0, 0, 0, 0.15), rgba(0, 0, 0, 0.5)); }
.tabs-scroll__rod::before, .tabs-scroll__rod::after { content: ''; position: absolute; top: -2px; width: 8px; height: 14px; border-radius: 3px; background: light-dark(#50535b, #c6c8cd); }
.tabs-scroll__rod::before { left: -4px; }
.tabs-scroll__rod::after { right: -4px; }
.tabs-scroll__panel { display: grid; justify-items: center; gap: 6px; height: 96px; padding: 14px 16px; background: linear-gradient(90deg, light-dark(#ebedf0, #232529), light-dark(#f3f4f7, #1a1c1f) 15%, light-dark(#f3f4f7, #1a1c1f) 85%, light-dark(#ebedf0, #232529)); color: light-dark(#50535b, #c6c8cd); font-family: Georgia, 'Times New Roman', serif; font-size: 12.5px; font-style: italic; line-height: 1.45; text-align: center; }
.tabs-scroll__panel b { color: light-dark(#373a40, #f1f2f3); font-size: 15px; font-style: normal; font-weight: 400; letter-spacing: 0.04em; }
.tabs-scroll__roll { position: absolute; left: -8px; right: -8px; bottom: -5px; height: 10px; border-radius: 5px; background: linear-gradient(light-dark(#5f626a, #a7abb2), light-dark(#cbced3, #393c41)); box-shadow: 0 3px 6px -2px light-dark(rgba(0, 0, 0, 0.15), rgba(0, 0, 0, 0.5)); }
.tabs-scroll[data-armed] .tabs-scroll__panel { animation: tabs-scroll-unroll 0.7s cubic-bezier(0.4, 0, 0.3, 1) both; }
.tabs-scroll[data-armed] .tabs-scroll__roll { animation: tabs-scroll-roll 0.7s cubic-bezier(0.4, 0, 0.3, 1) both; }
.tabs-scroll[data-flip='b'] .tabs-scroll__roll { animation-name: tabs-scroll-roll-b; }
@keyframes tabs-scroll-roll-b { from { transform: translateY(-96px); } to { transform: none; } }
@media (prefers-reduced-motion: reduce) {
.tabs-scroll__panel, .tabs-scroll__roll { animation: none !important; }
}function initTabsScroll(root) {
var list = root.querySelector('[role="tablist"]');
var tabs = Array.prototype.slice.call(list.querySelectorAll('[role="tab"]'));
var panels = root.querySelectorAll('[role="tabpanel"]');
var sel = tabs.findIndex(function (tab) { return tab.getAttribute('aria-selected') === 'true'; });
var flip = 0;
function select(i) {
if (i === sel) return;
var prev = sel;
sel = i;
// Armed on the first change, so nothing animates on load; each change flips data-flip
// between a and b, so the keyframes restart every time.
flip += 1;
root.setAttribute('data-armed', '');
root.setAttribute('data-flip', flip % 2 ? 'a' : 'b');
root.style.setProperty('--i', i);
root.style.setProperty('--p', prev);
tabs.forEach(function (tab, k) {
tab.setAttribute('aria-selected', String(k === i));
tab.tabIndex = k === i ? 0 : -1;
});
panels.forEach(function (panel, k) { panel.hidden = k !== i; });
}
function onClick(e) {
var tab = e.target.closest('[role="tab"]');
if (tab) select(tabs.indexOf(tab));
}
function onKeyDown(e) {
var n = tabs.length;
var next = { ArrowRight: (sel + 1) % n, ArrowLeft: (sel + n - 1) % n, Home: 0, End: n - 1 }[e.key];
if (next === undefined) return;
e.preventDefault();
select(next);
tabs[next].focus();
}
list.addEventListener('click', onClick);
list.addEventListener('keydown', onKeyDown);
return function () {
list.removeEventListener('click', onClick);
list.removeEventListener('keydown', onKeyDown);
};
}
document.querySelectorAll('.tabs-scroll').forEach(initTabsScroll);Goal: Create a "Scroll" tab set.
Visual behavior: Decree tabs on a scroll: pick a numeral and the parchment unrolls from the top rod with its roll travelling down, revealing the new decree.
Technique:
- The ARIA tabs pattern: a role="tablist" with an aria-label, buttons with role="tab", aria-selected and aria-controls, and role="tabpanel" panels labelled by their tab. Only the selected tab is in the Tab order (roving tabindex); the arrow keys, Home and End move between tabs and select as they go.
- The panel is revealed with a clip-path inset keyframe from the top while a rolled edge travels down with it on the same timing, so the paper seems to unroll from the roll.
- A data-armed attribute is set on the first change, so nothing plays on page load; a panel that is shown again restarts its entrance because it comes back from display: none.
- Effects that should replay on every change alternate between two identically written keyframes, chosen by a data-flip attribute that flips between a and b on each change, so the browser restarts them.
Accessibility: Real ARIA tabs: arrow keys, Home and End move between tabs, only the selected tab is in the Tab order, and each panel is labelled by its tab. Decoration is aria-hidden. Under prefers-reduced-motion the decree appears without unrolling.
My stack: {{USER_STACK}}
My styling: {{USER_STYLING}}
My constraints: {{USER_CONSTRAINTS}}
My colors: neutral only. Black, white and grays, no hues. Use the color values above as written, or my project's closest neutral tokens.
Return a single self-contained component. No dependencies.Goal: Create a "Scroll" tab set.
Visual behavior: Decree tabs on a scroll: pick a numeral and the parchment unrolls from the top rod with its roll travelling down, revealing the new decree.
Technique:
- The ARIA tabs pattern: a role="tablist" with an aria-label, buttons with role="tab", aria-selected and aria-controls, and role="tabpanel" panels labelled by their tab. Only the selected tab is in the Tab order (roving tabindex); the arrow keys, Home and End move between tabs and select as they go.
- The panel is revealed with a clip-path inset keyframe from the top while a rolled edge travels down with it on the same timing, so the paper seems to unroll from the roll.
- A data-armed attribute is set on the first change, so nothing plays on page load; a panel that is shown again restarts its entrance because it comes back from display: none.
- Effects that should replay on every change alternate between two identically written keyframes, chosen by a data-flip attribute that flips between a and b on each change, so the browser restarts them.
Accessibility: Real ARIA tabs: arrow keys, Home and End move between tabs, only the selected tab is in the Tab order, and each panel is labelled by its tab. Decoration is aria-hidden. Under prefers-reduced-motion the decree appears without unrolling.
My stack: {{USER_STACK}}
My styling: {{USER_STYLING}}
My constraints: {{USER_CONSTRAINTS}}
My colors: use my project's existing color tokens. The color values above are grayscale placeholders. Map each one by its role (surface, text, border, accent, glow) to my theme, and keep their relative lightness so contrast and the effect still read.
Return a single self-contained component. No dependencies.Paste into Claude, ChatGPT or Cursor after filling in {{USER_STACK}}, {{USER_STYLING}} and {{USER_CONSTRAINTS}}. Neutral keeps the greys you see here; Match my project asks the model to map them onto your own colour tokens.
Free to use in any project, commercial included. MIT-0, no attribution required. Licence
About this component
Decree tabs on a scroll: pick a numeral and the parchment unrolls from the top rod with its roll travelling down, revealing the new decree.
- Dependencies
- None
- Difficulty
- Intermediate
- Triggers
- click, state change
- Techniques
- keyframes, clip path, gradient
- Reduced motion
- Respected
- Theme
- Light and dark (follows your page's color-scheme)
Real ARIA tabs: arrow keys, Home and End move between tabs, only the selected tab is in the Tab order, and each panel is labelled by its tab. Decoration is aria-hidden. Under prefers-reduced-motion the decree appears without unrolling.