Gear
import { useId } from 'react';
const css = `
.radio-gear { --radio-gear-g: 0; display: flex; align-items: center; gap: 16px; }
.radio-gear:has(.radio-gear__input[value='r']:checked) { --radio-gear-g: 1; }
.radio-gear:has(.radio-gear__input[value='n']:checked) { --radio-gear-g: 2; }
.radio-gear:has(.radio-gear__input[value='d']:checked) { --radio-gear-g: 3; }
.radio-gear__display {
position: relative;
width: 40px;
height: 40px;
overflow: hidden;
border-radius: 8px;
background: light-dark(#fbfcfd, #121417);
box-shadow: inset 0 0 0 1px light-dark(#dbdde1, #2e3035);
}
.radio-gear__strip {
display: grid;
transform: translateY(calc(var(--radio-gear-g) * -40px));
transition: transform 0.35s cubic-bezier(0.3, 1.3, 0.5, 1);
}
.radio-gear__strip span {
display: grid;
place-items: center;
height: 40px;
color: light-dark(#373a40, #f1f2f3);
font-size: 22px;
font-weight: 600;
text-shadow: 0 0 8px color-mix(in oklab, light-dark(#373a40, #f1f2f3) 50%, transparent);
}
.radio-gear__gate { position: relative; width: 70px; height: 112px; }
.radio-gear__slot {
position: absolute;
left: 10px;
top: 6px;
width: 14px;
height: 100px;
border-radius: 7px;
background: light-dark(#fbfcfd, #121417);
box-shadow: inset 0 1px 3px light-dark(#fbfcfd, #121417), 0 0 0 1px light-dark(#dbdde1, #2e3035);
}
.radio-gear__knob {
position: absolute;
left: 3px;
top: 3px;
width: 28px;
height: 28px;
border-radius: 50%;
background: radial-gradient(circle at 38% 32%, light-dark(#42454c, #e5e6e9), light-dark(#6d7179, #7d8087) 60%, light-dark(#dbdde1, #2e3035));
box-shadow: 0 3px 6px color-mix(in oklab, light-dark(#fbfcfd, #121417) 60%, transparent);
transform: translateY(calc(var(--radio-gear-g) * 28px));
transition: transform 0.45s cubic-bezier(0.3, 1.45, 0.5, 1);
}
.radio-gear__letters { position: absolute; left: 38px; top: 0; display: grid; }
.radio-gear__letter {
position: relative;
display: grid;
place-items: center;
width: 28px;
height: 28px;
margin-top: 3px;
margin-bottom: -3px;
border-radius: 6px;
color: light-dark(#5f626a, #a7abb2);
font-size: 13px;
font-weight: 600;
cursor: pointer;
transition: color 0.2s;
}
.radio-gear__letter:hover { color: light-dark(#42454c, #e5e6e9); }
.radio-gear__input { position: absolute; width: 1px; height: 1px; margin: 0; opacity: 0; }
.radio-gear__letter:has(.radio-gear__input:focus-visible) { outline: 2px solid light-dark(#5f626a, #a7abb2); outline-offset: -2px; }
.radio-gear__letter:has(.radio-gear__input:checked) { color: light-dark(#373a40, #f1f2f3); }
@media (prefers-reduced-motion: reduce) {
.radio-gear * { transition-duration: 0.01s !important; }
}
`;
const GEARS = [
{ value: 'p', label: 'P', name: 'Park' },
{ value: 'r', label: 'R', name: 'Reverse' },
{ value: 'n', label: 'N', name: 'Neutral' },
{ value: 'd', label: 'D', name: 'Drive' },
];
export function GearRadio() {
const name = useId();
return (
<>
<style>
{css}
</style>
<div className="radio-gear">
<span className="radio-gear__display" aria-hidden="true">
<span className="radio-gear__strip">
{GEARS.map((g) => (
<span key={g.value}>{g.label}</span>
))}
</span>
</span>
<div className="radio-gear__gate">
<span className="radio-gear__slot" aria-hidden="true" />
<span className="radio-gear__knob" aria-hidden="true" />
<div className="radio-gear__letters" role="radiogroup" aria-label="Gear">
{GEARS.map((g, i) => (
<label key={g.value} className="radio-gear__letter">
<input className="radio-gear__input" type="radio" name={name} value={g.value} aria-label={g.name} defaultChecked={i === 0} />
<span aria-hidden="true">{g.label}</span>
</label>
))}
</div>
</div>
</div>
</>
);
}Markup where the component goes, CSS in your stylesheet. No JavaScript.
<div class="radio-gear">
<span class="radio-gear__display" aria-hidden="true">
<span class="radio-gear__strip">
<span>P</span>
<span>R</span>
<span>N</span>
<span>D</span>
</span>
</span>
<div class="radio-gear__gate">
<span class="radio-gear__slot" aria-hidden="true"></span>
<span class="radio-gear__knob" aria-hidden="true"></span>
<div class="radio-gear__letters" role="radiogroup" aria-label="Gear">
<label class="radio-gear__letter">
<input class="radio-gear__input" type="radio" aria-label="Park" name="radio-gear" checked="" value="p"/>
<span aria-hidden="true">P</span>
</label>
<label class="radio-gear__letter">
<input class="radio-gear__input" type="radio" aria-label="Reverse" name="radio-gear" value="r"/>
<span aria-hidden="true">R</span>
</label>
<label class="radio-gear__letter">
<input class="radio-gear__input" type="radio" aria-label="Neutral" name="radio-gear" value="n"/>
<span aria-hidden="true">N</span>
</label>
<label class="radio-gear__letter">
<input class="radio-gear__input" type="radio" aria-label="Drive" name="radio-gear" value="d"/>
<span aria-hidden="true">D</span>
</label>
</div>
</div>
</div>.radio-gear { --radio-gear-g: 0; display: flex; align-items: center; gap: 16px; }
.radio-gear:has(.radio-gear__input[value='r']:checked) { --radio-gear-g: 1; }
.radio-gear:has(.radio-gear__input[value='n']:checked) { --radio-gear-g: 2; }
.radio-gear:has(.radio-gear__input[value='d']:checked) { --radio-gear-g: 3; }
.radio-gear__display {
position: relative;
width: 40px;
height: 40px;
overflow: hidden;
border-radius: 8px;
background: light-dark(#fbfcfd, #121417);
box-shadow: inset 0 0 0 1px light-dark(#dbdde1, #2e3035);
}
.radio-gear__strip {
display: grid;
transform: translateY(calc(var(--radio-gear-g) * -40px));
transition: transform 0.35s cubic-bezier(0.3, 1.3, 0.5, 1);
}
.radio-gear__strip span {
display: grid;
place-items: center;
height: 40px;
color: light-dark(#373a40, #f1f2f3);
font-size: 22px;
font-weight: 600;
text-shadow: 0 0 8px color-mix(in oklab, light-dark(#373a40, #f1f2f3) 50%, transparent);
}
.radio-gear__gate { position: relative; width: 70px; height: 112px; }
.radio-gear__slot {
position: absolute;
left: 10px;
top: 6px;
width: 14px;
height: 100px;
border-radius: 7px;
background: light-dark(#fbfcfd, #121417);
box-shadow: inset 0 1px 3px light-dark(#fbfcfd, #121417), 0 0 0 1px light-dark(#dbdde1, #2e3035);
}
.radio-gear__knob {
position: absolute;
left: 3px;
top: 3px;
width: 28px;
height: 28px;
border-radius: 50%;
background: radial-gradient(circle at 38% 32%, light-dark(#42454c, #e5e6e9), light-dark(#6d7179, #7d8087) 60%, light-dark(#dbdde1, #2e3035));
box-shadow: 0 3px 6px color-mix(in oklab, light-dark(#fbfcfd, #121417) 60%, transparent);
transform: translateY(calc(var(--radio-gear-g) * 28px));
transition: transform 0.45s cubic-bezier(0.3, 1.45, 0.5, 1);
}
.radio-gear__letters { position: absolute; left: 38px; top: 0; display: grid; }
.radio-gear__letter {
position: relative;
display: grid;
place-items: center;
width: 28px;
height: 28px;
margin-top: 3px;
margin-bottom: -3px;
border-radius: 6px;
color: light-dark(#5f626a, #a7abb2);
font-size: 13px;
font-weight: 600;
cursor: pointer;
transition: color 0.2s;
}
.radio-gear__letter:hover { color: light-dark(#42454c, #e5e6e9); }
.radio-gear__input { position: absolute; width: 1px; height: 1px; margin: 0; opacity: 0; }
.radio-gear__letter:has(.radio-gear__input:focus-visible) { outline: 2px solid light-dark(#5f626a, #a7abb2); outline-offset: -2px; }
.radio-gear__letter:has(.radio-gear__input:checked) { color: light-dark(#373a40, #f1f2f3); }
@media (prefers-reduced-motion: reduce) {
.radio-gear * { transition-duration: 0.01s !important; }
}Goal: Create a "Gear" radio.
Visual behavior: A gear selector for P, R, N and D: the knob clicks along the gate to the gear you pick with a little overshoot, and the display rolls to the new letter.
Technique:
- Real native radios (visually hidden: absolute, 1x1, opacity 0) inside <label>s; the scene is aria-hidden and every state is read from the checked input with :has().
- One index set with :has() drives both the knob position and a strip of letters behind a window, each on its own overshooting curve. Pure CSS, no script.
Accessibility: A role="radiogroup" with an aria-label around native radio inputs sharing one name, so the arrow keys move the choice and Tab enters the group once; :focus-visible on the input outlines its option. Under prefers-reduced-motion the knob and the display change instantly.
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 "Gear" radio.
Visual behavior: A gear selector for P, R, N and D: the knob clicks along the gate to the gear you pick with a little overshoot, and the display rolls to the new letter.
Technique:
- Real native radios (visually hidden: absolute, 1x1, opacity 0) inside <label>s; the scene is aria-hidden and every state is read from the checked input with :has().
- One index set with :has() drives both the knob position and a strip of letters behind a window, each on its own overshooting curve. Pure CSS, no script.
Accessibility: A role="radiogroup" with an aria-label around native radio inputs sharing one name, so the arrow keys move the choice and Tab enters the group once; :focus-visible on the input outlines its option. Under prefers-reduced-motion the knob and the display change instantly.
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
A gear selector for P, R, N and D: the knob clicks along the gate to the gear you pick with a little overshoot, and the display rolls to the new letter.
- Dependencies
- None
- Difficulty
- Beginner
- Triggers
- click, state change, spring
- Techniques
- css variables, css transition, radial gradient
- Reduced motion
- Respected
- Theme
- Light and dark (follows your page's color-scheme)
A role="radiogroup" with an aria-label around native radio inputs sharing one name, so the arrow keys move the choice and Tab enters the group once; :focus-visible on the input outlines its option. Under prefers-reduced-motion the knob and the display change instantly.