Cube
import { useId, useRef, useState } from 'react';
const TABS = [
{ label: 'Q1', title: 'Q1 · Plan', body: 'Research, roadmap and the first hires.' },
{ label: 'Q2', title: 'Q2 · Build', body: 'The beta ships to forty teams.' },
{ label: 'Q3', title: 'Q3 · Grow', body: 'Pricing, partners and the launch.' },
{ label: 'Q4', title: 'Q4 · Tune', body: 'Speed, polish and a calm December.' },
];
const W = 240;
const css = `
.tabs-cube { width: ${W}px; }
.tabs-cube__list { display: grid; grid-template-columns: repeat(4, 1fr); gap: 4px; margin-bottom: 14px; }
.tabs-cube__tab { padding: 6px 0; border: 0; border-radius: 7px; background: light-dark(#f3f4f7, #1a1c1f); box-shadow: inset 0 0 0 1px light-dark(#ebedf0, #232529); color: light-dark(#5f626a, #a7abb2); font: inherit; font-size: 12px; font-weight: 600; cursor: pointer; transition: color 0.2s, box-shadow 0.2s; }
.tabs-cube__tab:hover { color: light-dark(#42454c, #e5e6e9); }
.tabs-cube__tab[aria-selected='true'] { color: light-dark(#373a40, #f1f2f3); box-shadow: inset 0 0 0 1px light-dark(#5f626a, #a7abb2); }
.tabs-cube__tab:focus-visible { outline: 2px solid light-dark(#5f626a, #a7abb2); outline-offset: 2px; }
.tabs-cube__scene { height: 92px; perspective: 900px; }
.tabs-cube__box { position: relative; width: 100%; height: 100%; transform-style: preserve-3d; transform: translateZ(-${W / 2}px) rotateY(calc(var(--tabs-cube-turn) * -90deg)); transition: transform 0.65s cubic-bezier(0.4, 0, 0.2, 1); }
.tabs-cube__panel { position: absolute; inset: 0; padding: 16px; border-radius: 12px; background: linear-gradient(160deg, light-dark(#dbdde1, #2e3035), light-dark(#ebedf0, #232529)); box-shadow: inset 0 0 0 1px light-dark(#cbced3, #393c41); transform: rotateY(calc(var(--k) * 90deg)) translateZ(${W / 2}px); backface-visibility: hidden; }
.tabs-cube__title { display: block; margin-bottom: 4px; color: light-dark(#373a40, #f1f2f3); font-size: 15px; font-weight: 600; }
.tabs-cube__body { color: light-dark(#50535b, #c6c8cd); font-size: 12.5px; line-height: 1.5; }
@media (prefers-reduced-motion: reduce) {
.tabs-cube__box { transition: none; }
}
`;
export function CubeTabs() {
const id = useId();
const [state, setState] = useState({ sel: 0, turn: 0 });
const tabs = useRef<(HTMLButtonElement | null)[]>([]);
const { sel } = state;
const select = (i: number) => {
// Turn the short way round, so Q4 to Q1 is one quarter turn, not three.
const step = ((i - sel + 6) % 4) - 2;
setState((s) => ({ sel: i, turn: s.turn + step }));
};
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-cube" style={{ '--tabs-cube-turn': state.turn } as React.CSSProperties}>
<div className="tabs-cube__list" role="tablist" aria-label="Quarter" onKeyDown={onKeyDown}>
{TABS.map((t, i) => (
<button
key={t.label}
ref={(el) => {
tabs.current[i] = el;
}}
className="tabs-cube__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-cube__scene">
<div className="tabs-cube__box">
{TABS.map((t, i) => (
<div
key={t.label}
className="tabs-cube__panel"
role="tabpanel"
id={`${id}-panel-${i}`}
aria-labelledby={`${id}-tab-${i}`}
aria-hidden={sel !== i}
inert={sel !== i}
style={{ '--k': i } as React.CSSProperties}
>
<span className="tabs-cube__title">{t.title}</span>
<span className="tabs-cube__body">{t.body}</span>
</div>
))}
</div>
</div>
</div>
</>
);
}Markup where the component goes, CSS in your stylesheet, script before </body>. In Vue, Svelte or Angular, call initTabsCube(el) on the mounted element instead.
<div class="tabs-cube" style="--tabs-cube-turn:0">
<div class="tabs-cube__list" role="tablist" aria-label="Quarter">
<button class="tabs-cube__tab" type="button" role="tab" id="tabs-cube-tab-0" aria-selected="true" aria-controls="tabs-cube-panel-0" tabindex="0">Q1</button>
<button class="tabs-cube__tab" type="button" role="tab" id="tabs-cube-tab-1" aria-selected="false" aria-controls="tabs-cube-panel-1" tabindex="-1">Q2</button>
<button class="tabs-cube__tab" type="button" role="tab" id="tabs-cube-tab-2" aria-selected="false" aria-controls="tabs-cube-panel-2" tabindex="-1">Q3</button>
<button class="tabs-cube__tab" type="button" role="tab" id="tabs-cube-tab-3" aria-selected="false" aria-controls="tabs-cube-panel-3" tabindex="-1">Q4</button>
</div>
<div class="tabs-cube__scene">
<div class="tabs-cube__box">
<div class="tabs-cube__panel" role="tabpanel" id="tabs-cube-panel-0" aria-labelledby="tabs-cube-tab-0" aria-hidden="false" style="--k:0">
<span class="tabs-cube__title">Q1 · Plan</span>
<span class="tabs-cube__body">Research, roadmap and the first hires.</span>
</div>
<div class="tabs-cube__panel" role="tabpanel" id="tabs-cube-panel-1" aria-labelledby="tabs-cube-tab-1" aria-hidden="true" inert="" style="--k:1">
<span class="tabs-cube__title">Q2 · Build</span>
<span class="tabs-cube__body">The beta ships to forty teams.</span>
</div>
<div class="tabs-cube__panel" role="tabpanel" id="tabs-cube-panel-2" aria-labelledby="tabs-cube-tab-2" aria-hidden="true" inert="" style="--k:2">
<span class="tabs-cube__title">Q3 · Grow</span>
<span class="tabs-cube__body">Pricing, partners and the launch.</span>
</div>
<div class="tabs-cube__panel" role="tabpanel" id="tabs-cube-panel-3" aria-labelledby="tabs-cube-tab-3" aria-hidden="true" inert="" style="--k:3">
<span class="tabs-cube__title">Q4 · Tune</span>
<span class="tabs-cube__body">Speed, polish and a calm December.</span>
</div>
</div>
</div>
</div>.tabs-cube { width: 240px; }
.tabs-cube__list { display: grid; grid-template-columns: repeat(4, 1fr); gap: 4px; margin-bottom: 14px; }
.tabs-cube__tab { padding: 6px 0; border: 0; border-radius: 7px; background: light-dark(#f3f4f7, #1a1c1f); box-shadow: inset 0 0 0 1px light-dark(#ebedf0, #232529); color: light-dark(#5f626a, #a7abb2); font: inherit; font-size: 12px; font-weight: 600; cursor: pointer; transition: color 0.2s, box-shadow 0.2s; }
.tabs-cube__tab:hover { color: light-dark(#42454c, #e5e6e9); }
.tabs-cube__tab[aria-selected='true'] { color: light-dark(#373a40, #f1f2f3); box-shadow: inset 0 0 0 1px light-dark(#5f626a, #a7abb2); }
.tabs-cube__tab:focus-visible { outline: 2px solid light-dark(#5f626a, #a7abb2); outline-offset: 2px; }
.tabs-cube__scene { height: 92px; perspective: 900px; }
.tabs-cube__box { position: relative; width: 100%; height: 100%; transform-style: preserve-3d; transform: translateZ(-120px) rotateY(calc(var(--tabs-cube-turn) * -90deg)); transition: transform 0.65s cubic-bezier(0.4, 0, 0.2, 1); }
.tabs-cube__panel { position: absolute; inset: 0; padding: 16px; border-radius: 12px; background: linear-gradient(160deg, light-dark(#dbdde1, #2e3035), light-dark(#ebedf0, #232529)); box-shadow: inset 0 0 0 1px light-dark(#cbced3, #393c41); transform: rotateY(calc(var(--k) * 90deg)) translateZ(120px); backface-visibility: hidden; }
.tabs-cube__title { display: block; margin-bottom: 4px; color: light-dark(#373a40, #f1f2f3); font-size: 15px; font-weight: 600; }
.tabs-cube__body { color: light-dark(#50535b, #c6c8cd); font-size: 12.5px; line-height: 1.5; }
@media (prefers-reduced-motion: reduce) {
.tabs-cube__box { transition: none; }
}function initTabsCube(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 turn = 0;
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;
});
// Every panel stays rendered for the 3D scene; the ones out of view are hidden from the keyboard and screen readers.
panels.forEach(function (panel, k) {
panel.setAttribute('aria-hidden', String(k !== i));
panel.inert = k !== i;
});
// Turn the short way round, so Q4 to Q1 is one quarter turn, not three.
turn += ((i - prev + 6) % 4) - 2;
root.style.setProperty('--tabs-cube-turn', turn);
}
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-cube').forEach(initTabsCube);Goal: Create a "Cube" tab set.
Visual behavior: Quarterly plans on the faces of a 3D cube: pick a quarter and the cube turns the short way round to that face.
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 four panels are faces of a box with transform-style: preserve-3d, each rotated and pushed out by half the width. A turn counter (a custom property) rotates the box; each change adds -1, 0, 1 or 2 quarter turns, whichever is shortest.
- Faces out of view are aria-hidden and inert rather than hidden, so the cube stays solid.
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 cube faces swap without turning.
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 "Cube" tab set.
Visual behavior: Quarterly plans on the faces of a 3D cube: pick a quarter and the cube turns the short way round to that face.
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 four panels are faces of a box with transform-style: preserve-3d, each rotated and pushed out by half the width. A turn counter (a custom property) rotates the box; each change adds -1, 0, 1 or 2 quarter turns, whichever is shortest.
- Faces out of view are aria-hidden and inert rather than hidden, so the cube stays solid.
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 cube faces swap without turning.
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
Quarterly plans on the faces of a 3D cube: pick a quarter and the cube turns the short way round to that face.
- Dependencies
- None
- Difficulty
- Advanced
- Triggers
- click, state change, 3d
- Techniques
- preserve 3d, perspective, css variables
- 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 cube faces swap without turning.