Route
import { useId } from 'react';
const css = `
.radio-route { --radio-route-k: 0; position: relative; width: 240px; height: 72px; }
.radio-route:has(.radio-route__input[value='york']:checked) { --radio-route-k: 1; }
.radio-route:has(.radio-route__input[value='durham']:checked) { --radio-route-k: 2; }
.radio-route__sleepers {
position: absolute;
left: 6px;
right: 6px;
top: 27px;
height: 10px;
background: repeating-linear-gradient(90deg, light-dark(#ebedf0, #232529) 0 3px, transparent 3px 9px);
}
.radio-route__track { position: absolute; left: 6px; right: 6px; top: 30px; height: 4px; border-radius: 2px; background: light-dark(#cbced3, #393c41); }
.radio-route__train {
position: absolute;
left: 13px;
top: 12px;
width: 34px;
height: 15px;
border-radius: 4px 10px 3px 3px;
background: linear-gradient(light-dark(#42454c, #e5e6e9), light-dark(#5f626a, #a7abb2));
transform: translateX(calc(var(--radio-route-k) * 90px));
transition: transform 0.9s cubic-bezier(0.5, 0, 0.25, 1);
z-index: 1;
}
.radio-route__train::before {
content: '';
position: absolute;
left: 4px;
top: 3px;
width: 21px;
height: 5px;
background: repeating-linear-gradient(90deg, light-dark(#dbdde1, #2e3035) 0 5px, transparent 5px 8px);
}
.radio-route__train::after {
content: '';
position: absolute;
left: 4px;
right: 4px;
bottom: -3px;
height: 5px;
background: radial-gradient(circle at 2.5px 2.5px, light-dark(#6d7179, #7d8087) 2px, transparent 2.5px) 0 0 / 9px 5px repeat-x;
}
.radio-route__stops { position: absolute; inset: 0; }
.radio-route__stop {
position: absolute;
top: 26px;
display: grid;
justify-items: center;
gap: 9px;
width: 64px;
margin-left: -32px;
color: light-dark(#5f626a, #a7abb2);
font-size: 12px;
font-weight: 600;
cursor: pointer;
transition: color 0.3s;
}
.radio-route__stop:hover { color: light-dark(#42454c, #e5e6e9); }
.radio-route__input { position: absolute; width: 1px; height: 1px; margin: 0; opacity: 0; }
.radio-route__dot {
width: 12px;
height: 12px;
border-radius: 50%;
background: light-dark(#f3f4f7, #1a1c1f);
box-shadow: inset 0 0 0 2px light-dark(#6d7179, #7d8087);
transition: background-color 0.3s, box-shadow 0.3s;
}
.radio-route__stop:has(.radio-route__input:focus-visible) .radio-route__dot { outline: 2px solid light-dark(#5f626a, #a7abb2); outline-offset: 3px; }
/* The platform lights once the train has pulled in. */
.radio-route__stop:has(.radio-route__input:checked) { color: light-dark(#373a40, #f1f2f3); transition-delay: 0.7s; }
.radio-route__stop:has(.radio-route__input:checked) .radio-route__dot {
background: light-dark(#373a40, #f1f2f3);
box-shadow: inset 0 0 0 2px light-dark(#373a40, #f1f2f3), 0 0 10px color-mix(in oklab, light-dark(#373a40, #f1f2f3) 50%, transparent);
transition-delay: 0.7s;
}
@media (prefers-reduced-motion: reduce) {
.radio-route *, .radio-route__stop { transition-duration: 0.01s !important; transition-delay: 0s !important; }
}
`;
const STOPS = [
{ value: 'leeds', label: 'Leeds', x: 30 },
{ value: 'york', label: 'York', x: 120 },
{ value: 'durham', label: 'Durham', x: 210 },
];
export function RouteRadio() {
const name = useId();
return (
<>
<style>
{css}
</style>
<div className="radio-route">
<span className="radio-route__sleepers" aria-hidden="true" />
<span className="radio-route__track" aria-hidden="true" />
<span className="radio-route__train" aria-hidden="true" />
<div className="radio-route__stops" role="radiogroup" aria-label="Destination">
{STOPS.map((s, i) => (
<label key={s.value} className="radio-route__stop" style={{ left: s.x }}>
<input className="radio-route__input" type="radio" name={name} value={s.value} defaultChecked={i === 0} />
<span className="radio-route__dot" aria-hidden="true" />
{s.label}
</label>
))}
</div>
</div>
</>
);
}Markup where the component goes, CSS in your stylesheet. No JavaScript.
<div class="radio-route">
<span class="radio-route__sleepers" aria-hidden="true"></span>
<span class="radio-route__track" aria-hidden="true"></span>
<span class="radio-route__train" aria-hidden="true"></span>
<div class="radio-route__stops" role="radiogroup" aria-label="Destination">
<label class="radio-route__stop" style="left:30px"><input class="radio-route__input" type="radio" name="radio-route" checked="" value="leeds"/><span class="radio-route__dot" aria-hidden="true"></span>Leeds</label>
<label class="radio-route__stop" style="left:120px"><input class="radio-route__input" type="radio" name="radio-route" value="york"/><span class="radio-route__dot" aria-hidden="true"></span>York</label>
<label class="radio-route__stop" style="left:210px"><input class="radio-route__input" type="radio" name="radio-route" value="durham"/><span class="radio-route__dot" aria-hidden="true"></span>Durham</label>
</div>
</div>.radio-route { --radio-route-k: 0; position: relative; width: 240px; height: 72px; }
.radio-route:has(.radio-route__input[value='york']:checked) { --radio-route-k: 1; }
.radio-route:has(.radio-route__input[value='durham']:checked) { --radio-route-k: 2; }
.radio-route__sleepers {
position: absolute;
left: 6px;
right: 6px;
top: 27px;
height: 10px;
background: repeating-linear-gradient(90deg, light-dark(#ebedf0, #232529) 0 3px, transparent 3px 9px);
}
.radio-route__track { position: absolute; left: 6px; right: 6px; top: 30px; height: 4px; border-radius: 2px; background: light-dark(#cbced3, #393c41); }
.radio-route__train {
position: absolute;
left: 13px;
top: 12px;
width: 34px;
height: 15px;
border-radius: 4px 10px 3px 3px;
background: linear-gradient(light-dark(#42454c, #e5e6e9), light-dark(#5f626a, #a7abb2));
transform: translateX(calc(var(--radio-route-k) * 90px));
transition: transform 0.9s cubic-bezier(0.5, 0, 0.25, 1);
z-index: 1;
}
.radio-route__train::before {
content: '';
position: absolute;
left: 4px;
top: 3px;
width: 21px;
height: 5px;
background: repeating-linear-gradient(90deg, light-dark(#dbdde1, #2e3035) 0 5px, transparent 5px 8px);
}
.radio-route__train::after {
content: '';
position: absolute;
left: 4px;
right: 4px;
bottom: -3px;
height: 5px;
background: radial-gradient(circle at 2.5px 2.5px, light-dark(#6d7179, #7d8087) 2px, transparent 2.5px) 0 0 / 9px 5px repeat-x;
}
.radio-route__stops { position: absolute; inset: 0; }
.radio-route__stop {
position: absolute;
top: 26px;
display: grid;
justify-items: center;
gap: 9px;
width: 64px;
margin-left: -32px;
color: light-dark(#5f626a, #a7abb2);
font-size: 12px;
font-weight: 600;
cursor: pointer;
transition: color 0.3s;
}
.radio-route__stop:hover { color: light-dark(#42454c, #e5e6e9); }
.radio-route__input { position: absolute; width: 1px; height: 1px; margin: 0; opacity: 0; }
.radio-route__dot {
width: 12px;
height: 12px;
border-radius: 50%;
background: light-dark(#f3f4f7, #1a1c1f);
box-shadow: inset 0 0 0 2px light-dark(#6d7179, #7d8087);
transition: background-color 0.3s, box-shadow 0.3s;
}
.radio-route__stop:has(.radio-route__input:focus-visible) .radio-route__dot { outline: 2px solid light-dark(#5f626a, #a7abb2); outline-offset: 3px; }
/* The platform lights once the train has pulled in. */
.radio-route__stop:has(.radio-route__input:checked) { color: light-dark(#373a40, #f1f2f3); transition-delay: 0.7s; }
.radio-route__stop:has(.radio-route__input:checked) .radio-route__dot {
background: light-dark(#373a40, #f1f2f3);
box-shadow: inset 0 0 0 2px light-dark(#373a40, #f1f2f3), 0 0 10px color-mix(in oklab, light-dark(#373a40, #f1f2f3) 50%, transparent);
transition-delay: 0.7s;
}
@media (prefers-reduced-motion: reduce) {
.radio-route *, .radio-route__stop { transition-duration: 0.01s !important; transition-delay: 0s !important; }
}Goal: Create a "Route" radio.
Visual behavior: A destination picker on a railway line: choose a station and the train pulls along the track to it, accelerating and braking in; the platform lamp and its name light as it arrives.
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().
- The chosen station sets one CSS variable on the root with :has(); the train is translated by that index times the station spacing on an ease-in-out curve.
- The lamp and label of the checked station light after a delay, so they wait for the train. 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 train moves 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 "Route" radio.
Visual behavior: A destination picker on a railway line: choose a station and the train pulls along the track to it, accelerating and braking in; the platform lamp and its name light as it arrives.
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().
- The chosen station sets one CSS variable on the root with :has(); the train is translated by that index times the station spacing on an ease-in-out curve.
- The lamp and label of the checked station light after a delay, so they wait for the train. 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 train moves 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 destination picker on a railway line: choose a station and the train pulls along the track to it, accelerating and braking in; the platform lamp and its name light as it arrives.
- Dependencies
- None
- Difficulty
- Beginner
- Triggers
- click, state change, glow
- Techniques
- css variables, css transition, 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 train moves instantly.