Headline
import { useId, useRef, useState } from 'react';
const ITEMS = [
{ label: 'City', head: 'New bridge opens at dawn', kicker: 'Crowds cross before the ribbon is cut' },
{ label: 'Arts', head: 'The lost mural returns', kicker: 'Forty years in a basement, restored' },
{ label: 'Sport', head: 'Rowers win in fog', kicker: 'A finish nobody on the bank could see' },
];
const css = `
@keyframes tabs-headline-spin { 0% { transform: rotate(-540deg) scale(0.1); opacity: 0; } 70% { transform: rotate(8deg) scale(1.04); opacity: 1; } 100% { transform: none; opacity: 1; } }
.tabs-headline { display: grid; justify-items: center; gap: 12px; width: 250px; }
.tabs-headline__list { display: flex; gap: 14px; border-bottom: 1px solid light-dark(#dbdde1, #2e3035); }
.tabs-headline__tab { position: relative; padding: 0; border: 0; background: none; font: inherit; cursor: pointer; }
.tabs-headline__tab:focus-visible { outline: 2px solid light-dark(#50535b, #c6c8cd); outline-offset: 3px; border-radius: 8px; }
.tabs-headline__tab { padding: 4px 2px 7px; color: light-dark(#5f626a, #a7abb2); font-size: 11px; font-weight: 600; letter-spacing: 0.14em; text-transform: uppercase; box-shadow: inset 0 -2px 0 transparent; transition: color 0.2s, box-shadow 0.2s; }
.tabs-headline__tab[aria-selected='true'] { color: light-dark(#373a40, #f1f2f3); box-shadow: inset 0 -2px 0 light-dark(#373a40, #f1f2f3); }
.tabs-headline__panel { width: 210px; padding: 10px 12px 12px; border-radius: 2px; background: light-dark(#f3f4f7, #1a1c1f); box-shadow: inset 0 0 0 1px light-dark(#cbced3, #393c41), 0 12px 22px -12px light-dark(rgba(0, 0, 0, 0.21), rgba(0, 0, 0, 0.7)); }
.tabs-headline[data-armed] .tabs-headline__panel { animation: tabs-headline-spin 0.8s cubic-bezier(0.25, 0.8, 0.35, 1) both; }
.tabs-headline__mast { display: flex; justify-content: space-between; padding-bottom: 5px; border-bottom: 2px solid light-dark(#50535b, #c6c8cd); color: light-dark(#373a40, #f1f2f3); font-family: Georgia, 'Times New Roman', serif; font-size: 13px; font-weight: 600; }
.tabs-headline__mast small { align-self: flex-end; color: light-dark(#5f626a, #a7abb2); font-family: inherit; font-size: 8px; font-weight: 400; letter-spacing: 0.1em; }
.tabs-headline__head { margin: 8px 0 3px; color: light-dark(#373a40, #f1f2f3); font-family: Georgia, 'Times New Roman', serif; font-size: 17px; line-height: 1.1; }
.tabs-headline__kick { color: light-dark(#50535b, #c6c8cd); font-size: 10.5px; font-style: italic; }
.tabs-headline__cols { display: grid; grid-template-columns: 1fr 1fr 1fr; gap: 6px; margin-top: 8px; height: 22px; background: repeating-linear-gradient(light-dark(#cbced3, #393c41) 0 1.5px, transparent 1.5px 5px); -webkit-mask: linear-gradient(90deg, #000 30%, transparent 30% 35%, #000 35% 65%, transparent 65% 70%, #000 70%); mask: linear-gradient(90deg, #000 30%, transparent 30% 35%, #000 35% 65%, transparent 65% 70%, #000 70%); }
@media (prefers-reduced-motion: reduce) {
.tabs-headline__panel { animation: none !important; }
}
`;
export function HeadlineTabs() {
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-headline"
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-headline__list" role="tablist" aria-label="Sections" onKeyDown={onKeyDown}>
{ITEMS.map((t, i) => (
<button
key={t.label}
ref={(el) => {
tabs.current[i] = el;
}}
className="tabs-headline__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>
{ITEMS.map((t, i) => (
<div key={t.label} className="tabs-headline__panel" role="tabpanel" id={`${id}-panel-${i}`} aria-labelledby={`${id}-tab-${i}`} hidden={sel !== i}>
<div className="tabs-headline__mast" aria-hidden="true">
The Daily <small>EST. 1898</small>
</div>
<div className="tabs-headline__head">{t.head}</div>
<div className="tabs-headline__kick">{t.kicker}</div>
<div className="tabs-headline__cols" aria-hidden="true" />
</div>
))}
</div>
</>
);
}Markup where the component goes, CSS in your stylesheet, script before </body>. In Vue, Svelte or Angular, call initTabsHeadline(el) on the mounted element instead.
<div class="tabs-headline" style="--i:0;--p:0">
<div class="tabs-headline__list" role="tablist" aria-label="Sections">
<button class="tabs-headline__tab" type="button" role="tab" id="tabs-headline-tab-0" aria-selected="true" aria-controls="tabs-headline-panel-0" tabindex="0">City</button>
<button class="tabs-headline__tab" type="button" role="tab" id="tabs-headline-tab-1" aria-selected="false" aria-controls="tabs-headline-panel-1" tabindex="-1">Arts</button>
<button class="tabs-headline__tab" type="button" role="tab" id="tabs-headline-tab-2" aria-selected="false" aria-controls="tabs-headline-panel-2" tabindex="-1">Sport</button>
</div>
<div class="tabs-headline__panel" role="tabpanel" id="tabs-headline-panel-0" aria-labelledby="tabs-headline-tab-0">
<div class="tabs-headline__mast" aria-hidden="true">The Daily <small>EST. 1898</small></div>
<div class="tabs-headline__head">New bridge opens at dawn</div>
<div class="tabs-headline__kick">Crowds cross before the ribbon is cut</div>
<div class="tabs-headline__cols" aria-hidden="true"></div>
</div>
<div class="tabs-headline__panel" role="tabpanel" id="tabs-headline-panel-1" aria-labelledby="tabs-headline-tab-1" hidden="">
<div class="tabs-headline__mast" aria-hidden="true">The Daily <small>EST. 1898</small></div>
<div class="tabs-headline__head">The lost mural returns</div>
<div class="tabs-headline__kick">Forty years in a basement, restored</div>
<div class="tabs-headline__cols" aria-hidden="true"></div>
</div>
<div class="tabs-headline__panel" role="tabpanel" id="tabs-headline-panel-2" aria-labelledby="tabs-headline-tab-2" hidden="">
<div class="tabs-headline__mast" aria-hidden="true">The Daily <small>EST. 1898</small></div>
<div class="tabs-headline__head">Rowers win in fog</div>
<div class="tabs-headline__kick">A finish nobody on the bank could see</div>
<div class="tabs-headline__cols" aria-hidden="true"></div>
</div>
</div>@keyframes tabs-headline-spin { 0% { transform: rotate(-540deg) scale(0.1); opacity: 0; } 70% { transform: rotate(8deg) scale(1.04); opacity: 1; } 100% { transform: none; opacity: 1; } }
.tabs-headline { display: grid; justify-items: center; gap: 12px; width: 250px; }
.tabs-headline__list { display: flex; gap: 14px; border-bottom: 1px solid light-dark(#dbdde1, #2e3035); }
.tabs-headline__tab { position: relative; padding: 0; border: 0; background: none; font: inherit; cursor: pointer; }
.tabs-headline__tab:focus-visible { outline: 2px solid light-dark(#50535b, #c6c8cd); outline-offset: 3px; border-radius: 8px; }
.tabs-headline__tab { padding: 4px 2px 7px; color: light-dark(#5f626a, #a7abb2); font-size: 11px; font-weight: 600; letter-spacing: 0.14em; text-transform: uppercase; box-shadow: inset 0 -2px 0 transparent; transition: color 0.2s, box-shadow 0.2s; }
.tabs-headline__tab[aria-selected='true'] { color: light-dark(#373a40, #f1f2f3); box-shadow: inset 0 -2px 0 light-dark(#373a40, #f1f2f3); }
.tabs-headline__panel { width: 210px; padding: 10px 12px 12px; border-radius: 2px; background: light-dark(#f3f4f7, #1a1c1f); box-shadow: inset 0 0 0 1px light-dark(#cbced3, #393c41), 0 12px 22px -12px light-dark(rgba(0, 0, 0, 0.21), rgba(0, 0, 0, 0.7)); }
.tabs-headline[data-armed] .tabs-headline__panel { animation: tabs-headline-spin 0.8s cubic-bezier(0.25, 0.8, 0.35, 1) both; }
.tabs-headline__mast { display: flex; justify-content: space-between; padding-bottom: 5px; border-bottom: 2px solid light-dark(#50535b, #c6c8cd); color: light-dark(#373a40, #f1f2f3); font-family: Georgia, 'Times New Roman', serif; font-size: 13px; font-weight: 600; }
.tabs-headline__mast small { align-self: flex-end; color: light-dark(#5f626a, #a7abb2); font-family: inherit; font-size: 8px; font-weight: 400; letter-spacing: 0.1em; }
.tabs-headline__head { margin: 8px 0 3px; color: light-dark(#373a40, #f1f2f3); font-family: Georgia, 'Times New Roman', serif; font-size: 17px; line-height: 1.1; }
.tabs-headline__kick { color: light-dark(#50535b, #c6c8cd); font-size: 10.5px; font-style: italic; }
.tabs-headline__cols { display: grid; grid-template-columns: 1fr 1fr 1fr; gap: 6px; margin-top: 8px; height: 22px; background: repeating-linear-gradient(light-dark(#cbced3, #393c41) 0 1.5px, transparent 1.5px 5px); -webkit-mask: linear-gradient(90deg, #000 30%, transparent 30% 35%, #000 35% 65%, transparent 65% 70%, #000 70%); mask: linear-gradient(90deg, #000 30%, transparent 30% 35%, #000 35% 65%, transparent 65% 70%, #000 70%); }
@media (prefers-reduced-motion: reduce) {
.tabs-headline__panel { animation: none !important; }
}function initTabsHeadline(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-headline').forEach(initTabsHeadline);Goal: Create a "Headline" tab set.
Visual behavior: Newspaper section tabs: pick a section and the front page spins in from nowhere with its new headline, like a newsreel stop-press.
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 enters with a keyframe from rotate(-540deg) scale(0.1) through a small overshoot to rest, so the page spins in from the distance.
- The masthead and column rules are decoration; the headline and kicker are the panel text.
- 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.
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 page simply appears.
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 "Headline" tab set.
Visual behavior: Newspaper section tabs: pick a section and the front page spins in from nowhere with its new headline, like a newsreel stop-press.
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 enters with a keyframe from rotate(-540deg) scale(0.1) through a small overshoot to rest, so the page spins in from the distance.
- The masthead and column rules are decoration; the headline and kicker are the panel text.
- 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.
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 page simply appears.
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
Newspaper section tabs: pick a section and the front page spins in from nowhere with its new headline, like a newsreel stop-press.
- Dependencies
- None
- Difficulty
- Beginner
- Triggers
- click, state change, spring
- Techniques
- keyframes, transform only, text animation
- 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 page simply appears.