Decode
import { useEffect, useId, useRef, useState } from 'react';
const TABS = [
{ label: 'North', title: 'PROJECT NORTH', body: 'Mapping the coast with low-flying drones.' },
{ label: 'Harbor', title: 'PROJECT HARBOR', body: 'A quieter engine for the night ferries.' },
{ label: 'Summit', title: 'PROJECT SUMMIT', body: 'Weather stations on the three high peaks.' },
];
const GLYPHS = '#%&*+=<>/\\[]{}?!0123456789ABCDEFXYZ';
const FRAMES = 22;
const css = `
@keyframes tabs-decode-body { from { opacity: 0; } }
.tabs-decode { width: 250px; }
.tabs-decode__list { display: grid; grid-template-columns: repeat(3, 1fr); gap: 4px; margin-bottom: 12px; }
.tabs-decode__tab { padding: 6px 0; border: 0; border-radius: 6px; background: light-dark(#f3f4f7, #1a1c1f); box-shadow: inset 0 0 0 1px light-dark(#ebedf0, #232529); color: light-dark(#5f626a, #a7abb2); font: inherit; font-family: ui-monospace, SFMono-Regular, Menlo, monospace; font-size: 11px; letter-spacing: 0.06em; text-transform: uppercase; cursor: pointer; transition: color 0.2s, box-shadow 0.2s; }
.tabs-decode__tab:hover { color: light-dark(#42454c, #e5e6e9); }
.tabs-decode__tab[aria-selected='true'] { color: light-dark(#373a40, #f1f2f3); box-shadow: inset 0 0 0 1px light-dark(#50535b, #c6c8cd); }
.tabs-decode__tab:focus-visible { outline: 2px solid light-dark(#5f626a, #a7abb2); outline-offset: 2px; }
.tabs-decode__panel { min-height: 72px; padding: 0 4px; }
.tabs-decode__title { display: block; margin-bottom: 6px; color: light-dark(#373a40, #f1f2f3); font-family: ui-monospace, SFMono-Regular, Menlo, monospace; font-size: 15px; font-weight: 600; letter-spacing: 0.06em; white-space: pre; }
.tabs-decode__body { display: block; color: light-dark(#50535b, #c6c8cd); font-size: 12.5px; line-height: 1.5; }
.tabs-decode[data-armed] .tabs-decode__body { animation: tabs-decode-body 0.5s ease-out 0.25s backwards; }
.tabs-decode__sr { position: absolute; width: 1px; height: 1px; overflow: hidden; clip-path: inset(50%); white-space: nowrap; }
@media (prefers-reduced-motion: reduce) {
.tabs-decode__body { animation: none !important; }
}
`;
// Frame f of the decode: each letter cycles through symbols, then locks in, left to right.
const scramble = (text: string, f: number) =>
text
.split('')
.map((c, i) => (c === ' ' || f >= FRAMES || f > i * 1.3 + 4 ? c : GLYPHS[(i * 7 + f * 13) % GLYPHS.length]))
.join('');
export function DecodeTabs() {
const id = useId();
const [sel, setSel] = useState(0);
const [frame, setFrame] = useState(FRAMES);
const tabs = useRef<(HTMLButtonElement | null)[]>([]);
useEffect(() => {
if (frame >= FRAMES) return;
const t = setTimeout(() => setFrame((f) => f + 1), 35);
return () => clearTimeout(t);
}, [frame]);
const select = (i: number) => {
if (i === sel) return;
setSel(i);
setFrame(window.matchMedia('(prefers-reduced-motion: reduce)').matches ? FRAMES : 0);
};
const onKeyDown = (e: React.KeyboardEvent) => {
const n = TABS.length;
const 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.current[next]?.focus();
};
return (
<>
<style>
{css}
</style>
<div className="tabs-decode" data-armed={frame < FRAMES ? '' : undefined}>
<div className="tabs-decode__list" role="tablist" aria-label="Projects" onKeyDown={onKeyDown}>
{TABS.map((t, i) => (
<button
key={t.label}
ref={(el) => {
tabs.current[i] = el;
}}
className="tabs-decode__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>
{TABS.map((t, i) => (
<div key={t.label} className="tabs-decode__panel" role="tabpanel" id={`${id}-panel-${i}`} aria-labelledby={`${id}-tab-${i}`} hidden={sel !== i}>
<span className="tabs-decode__sr">{t.title}</span>
<span className="tabs-decode__title" aria-hidden="true">
{sel === i ? scramble(t.title, frame) : t.title}
</span>
<span className="tabs-decode__body">{t.body}</span>
</div>
))}
</div>
</>
);
}Markup where the component goes, CSS in your stylesheet, script before </body>. In Vue, Svelte or Angular, call initTabsDecode(el) on the mounted element instead.
<div class="tabs-decode">
<div class="tabs-decode__list" role="tablist" aria-label="Projects">
<button class="tabs-decode__tab" type="button" role="tab" id="tabs-decode-tab-0" aria-selected="true" aria-controls="tabs-decode-panel-0" tabindex="0">North</button>
<button class="tabs-decode__tab" type="button" role="tab" id="tabs-decode-tab-1" aria-selected="false" aria-controls="tabs-decode-panel-1" tabindex="-1">Harbor</button>
<button class="tabs-decode__tab" type="button" role="tab" id="tabs-decode-tab-2" aria-selected="false" aria-controls="tabs-decode-panel-2" tabindex="-1">Summit</button>
</div>
<div class="tabs-decode__panel" role="tabpanel" id="tabs-decode-panel-0" aria-labelledby="tabs-decode-tab-0">
<span class="tabs-decode__sr">PROJECT NORTH</span>
<span class="tabs-decode__title" aria-hidden="true">PROJECT NORTH</span>
<span class="tabs-decode__body">Mapping the coast with low-flying drones.</span>
</div>
<div class="tabs-decode__panel" role="tabpanel" id="tabs-decode-panel-1" aria-labelledby="tabs-decode-tab-1" hidden="">
<span class="tabs-decode__sr">PROJECT HARBOR</span>
<span class="tabs-decode__title" aria-hidden="true">PROJECT HARBOR</span>
<span class="tabs-decode__body">A quieter engine for the night ferries.</span>
</div>
<div class="tabs-decode__panel" role="tabpanel" id="tabs-decode-panel-2" aria-labelledby="tabs-decode-tab-2" hidden="">
<span class="tabs-decode__sr">PROJECT SUMMIT</span>
<span class="tabs-decode__title" aria-hidden="true">PROJECT SUMMIT</span>
<span class="tabs-decode__body">Weather stations on the three high peaks.</span>
</div>
</div>@keyframes tabs-decode-body { from { opacity: 0; } }
.tabs-decode { width: 250px; }
.tabs-decode__list { display: grid; grid-template-columns: repeat(3, 1fr); gap: 4px; margin-bottom: 12px; }
.tabs-decode__tab { padding: 6px 0; border: 0; border-radius: 6px; background: light-dark(#f3f4f7, #1a1c1f); box-shadow: inset 0 0 0 1px light-dark(#ebedf0, #232529); color: light-dark(#5f626a, #a7abb2); font: inherit; font-family: ui-monospace, SFMono-Regular, Menlo, monospace; font-size: 11px; letter-spacing: 0.06em; text-transform: uppercase; cursor: pointer; transition: color 0.2s, box-shadow 0.2s; }
.tabs-decode__tab:hover { color: light-dark(#42454c, #e5e6e9); }
.tabs-decode__tab[aria-selected='true'] { color: light-dark(#373a40, #f1f2f3); box-shadow: inset 0 0 0 1px light-dark(#50535b, #c6c8cd); }
.tabs-decode__tab:focus-visible { outline: 2px solid light-dark(#5f626a, #a7abb2); outline-offset: 2px; }
.tabs-decode__panel { min-height: 72px; padding: 0 4px; }
.tabs-decode__title { display: block; margin-bottom: 6px; color: light-dark(#373a40, #f1f2f3); font-family: ui-monospace, SFMono-Regular, Menlo, monospace; font-size: 15px; font-weight: 600; letter-spacing: 0.06em; white-space: pre; }
.tabs-decode__body { display: block; color: light-dark(#50535b, #c6c8cd); font-size: 12.5px; line-height: 1.5; }
.tabs-decode[data-armed] .tabs-decode__body { animation: tabs-decode-body 0.5s ease-out 0.25s backwards; }
.tabs-decode__sr { position: absolute; width: 1px; height: 1px; overflow: hidden; clip-path: inset(50%); white-space: nowrap; }
@media (prefers-reduced-motion: reduce) {
.tabs-decode__body { animation: none !important; }
}function initTabsDecode(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 GLYPHS = '#%&*+=<>/\\[]{}?!0123456789ABCDEFXYZ';
var FRAMES = 22;
var timer;
var titles = Array.prototype.map.call(panels, function (panel) { return panel.querySelector('.tabs-decode__title'); });
var words = Array.prototype.map.call(panels, function (panel) { return panel.querySelector('.tabs-decode__sr').textContent; });
// Frame f of the decode: each letter cycles through symbols, then locks in, left to right.
function scramble(text, f) {
return text.split('').map(function (c, k) {
return c === ' ' || f >= FRAMES || f > k * 1.3 + 4 ? c : GLYPHS[(k * 7 + f * 13) % GLYPHS.length];
}).join('');
}
function select(i) {
if (i === sel) return;
var prev = sel;
sel = i;
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; });
clearTimeout(timer);
titles[prev].textContent = words[prev];
if (window.matchMedia('(prefers-reduced-motion: reduce)').matches) {
titles[i].textContent = words[i];
root.removeAttribute('data-armed');
return;
}
var frame = 0;
root.setAttribute('data-armed', '');
(function step() {
titles[i].textContent = scramble(words[i], frame);
if (frame++ < FRAMES) timer = setTimeout(step, 35);
else root.removeAttribute('data-armed');
})();
}
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 () {
clearTimeout(timer);
list.removeEventListener('click', onClick);
list.removeEventListener('keydown', onKeyDown);
};
}
document.querySelectorAll('.tabs-decode').forEach(initTabsDecode);Goal: Create a "Decode" tab set.
Visual behavior: Project tabs where the heading scrambles through symbols and locks into the new words letter by letter, left to right.
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.
- Over 22 frames 35ms apart, each letter shows a symbol picked from its position and the frame (no randomness) until its own lock-in frame, which comes later along the word.
- The scrambled heading is aria-hidden; a visually hidden copy carries the real words.
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. Screen readers get the real heading. Under prefers-reduced-motion it changes without scrambling.
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 "Decode" tab set.
Visual behavior: Project tabs where the heading scrambles through symbols and locks into the new words letter by letter, left to right.
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.
- Over 22 frames 35ms apart, each letter shows a symbol picked from its position and the frame (no randomness) until its own lock-in frame, which comes later along the word.
- The scrambled heading is aria-hidden; a visually hidden copy carries the real words.
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. Screen readers get the real heading. Under prefers-reduced-motion it changes without scrambling.
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
Project tabs where the heading scrambles through symbols and locks into the new words letter by letter, left to right.
- Dependencies
- None
- Difficulty
- Intermediate
- Triggers
- click, state change, keyframe
- Techniques
- interval, text animation, state machine
- 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. Screen readers get the real heading. Under prefers-reduced-motion it changes without scrambling.