Altitude
import { useId } from 'react';
const css = `
.radio-altitude { --radio-altitude-p: 0; --radio-altitude-k: 0; display: grid; justify-items: center; gap: 12px; }
.radio-altitude:has(.radio-altitude__input[value='camp']:checked) { --radio-altitude-p: 0.55; --radio-altitude-k: 1; }
.radio-altitude:has(.radio-altitude__input[value='summit']:checked) { --radio-altitude-p: 1; --radio-altitude-k: 2; }
.radio-altitude__map { position: relative; width: 200px; height: 100px; }
.radio-altitude__map svg { position: absolute; inset: 0; width: 200px; height: 100px; }
.radio-altitude__range { fill: light-dark(#ebedf0, #232529); }
.radio-altitude__peak { fill: light-dark(#dbdde1, #2e3035); }
.radio-altitude__snow { fill: light-dark(#50535b, #c6c8cd); }
.radio-altitude__trail { fill: none; stroke: light-dark(#6d7179, #7d8087); stroke-width: 1.4; stroke-dasharray: 2 3; stroke-linecap: round; }
.radio-altitude__walked {
fill: none;
stroke: light-dark(#373a40, #f1f2f3);
stroke-width: 2;
stroke-linecap: round;
stroke-linejoin: round;
stroke-dasharray: 1;
stroke-dashoffset: calc(1 - var(--radio-altitude-p));
transition: stroke-dashoffset 1.1s cubic-bezier(0.45, 0, 0.3, 1);
}
.radio-altitude__climber {
position: absolute;
left: 0;
top: 0;
width: 10px;
height: 10px;
border-radius: 50%;
background: light-dark(#373a40, #f1f2f3);
box-shadow: 0 0 0 3px color-mix(in oklab, light-dark(#373a40, #f1f2f3) 25%, transparent);
offset-path: path('M20 92L60 80L44 66L86 54L70 40L104 28L120 12');
offset-rotate: 0deg;
offset-distance: calc(var(--radio-altitude-p) * 100%);
transition: offset-distance 1.1s cubic-bezier(0.45, 0, 0.3, 1);
}
.radio-altitude__readout { position: absolute; right: 0; top: 0; height: 16px; overflow: hidden; }
.radio-altitude__strip { display: grid; transform: translateY(calc(var(--radio-altitude-k) * -16px)); transition: transform 0.5s cubic-bezier(0.3, 1.3, 0.5, 1) 0.4s; }
.radio-altitude__strip span { height: 16px; color: light-dark(#42454c, #e5e6e9); font-size: 11px; font-weight: 600; line-height: 16px; text-align: right; font-variant-numeric: tabular-nums; }
.radio-altitude__opts { display: flex; gap: 4px; padding: 4px; border-radius: 10px; background: light-dark(#f3f4f7, #1a1c1f); box-shadow: inset 0 0 0 1px light-dark(#dbdde1, #2e3035); }
.radio-altitude__opt {
position: relative;
padding: 5px 12px;
border-radius: 7px;
color: light-dark(#5f626a, #a7abb2);
font-size: 12px;
font-weight: 600;
cursor: pointer;
transition: color 0.2s, background-color 0.2s;
}
.radio-altitude__opt:hover { color: light-dark(#42454c, #e5e6e9); }
.radio-altitude__input { position: absolute; width: 1px; height: 1px; margin: 0; opacity: 0; }
.radio-altitude__opt:has(.radio-altitude__input:focus-visible) { outline: 2px solid light-dark(#5f626a, #a7abb2); outline-offset: 2px; }
.radio-altitude__opt:has(.radio-altitude__input:checked) { background: light-dark(#42454c, #e5e6e9); color: light-dark(#fbfcfd, #121417); }
@media (prefers-reduced-motion: reduce) {
.radio-altitude * { transition-duration: 0.01s !important; transition-delay: 0s !important; }
}
`;
const TRAIL = 'M20 92L60 80L44 66L86 54L70 40L104 28L120 12';
const STOPS = [
{ value: 'base', label: 'Base', alt: '1,200 m' },
{ value: 'camp', label: 'Camp', alt: '4,100 m' },
{ value: 'summit', label: 'Summit', alt: '5,364 m' },
];
export function AltitudeRadio() {
const name = useId();
return (
<>
<style>
{css}
</style>
<div className="radio-altitude">
<span className="radio-altitude__map" aria-hidden="true">
<svg viewBox="0 0 200 100">
<path className="radio-altitude__range" d="M0 100L36 58L62 76L150 30L200 70V100Z" />
<path className="radio-altitude__peak" d="M4 100L120 8L196 100Z" />
<path className="radio-altitude__snow" d="M106 19L120 8L134 19L127 17L120 22L113 17Z" />
<path className="radio-altitude__trail" d={TRAIL} />
<path className="radio-altitude__walked" pathLength={1} d={TRAIL} />
</svg>
<span className="radio-altitude__climber" />
<span className="radio-altitude__readout">
<span className="radio-altitude__strip">
{STOPS.map((s) => (
<span key={s.value}>{s.alt}</span>
))}
</span>
</span>
</span>
<div className="radio-altitude__opts" role="radiogroup" aria-label="Waypoint">
{STOPS.map((s, i) => (
<label key={s.value} className="radio-altitude__opt">
<input className="radio-altitude__input" type="radio" name={name} value={s.value} defaultChecked={i === 0} />
{s.label}
</label>
))}
</div>
</div>
</>
);
}Markup where the component goes, CSS in your stylesheet. No JavaScript.
<div class="radio-altitude">
<span class="radio-altitude__map" aria-hidden="true">
<svg viewBox="0 0 200 100">
<path class="radio-altitude__range" d="M0 100L36 58L62 76L150 30L200 70V100Z"></path>
<path class="radio-altitude__peak" d="M4 100L120 8L196 100Z"></path>
<path class="radio-altitude__snow" d="M106 19L120 8L134 19L127 17L120 22L113 17Z"></path>
<path class="radio-altitude__trail" d="M20 92L60 80L44 66L86 54L70 40L104 28L120 12"></path>
<path class="radio-altitude__walked" pathLength="1" d="M20 92L60 80L44 66L86 54L70 40L104 28L120 12"></path>
</svg>
<span class="radio-altitude__climber"></span>
<span class="radio-altitude__readout">
<span class="radio-altitude__strip">
<span>1,200 m</span>
<span>4,100 m</span>
<span>5,364 m</span>
</span>
</span>
</span>
<div class="radio-altitude__opts" role="radiogroup" aria-label="Waypoint">
<label class="radio-altitude__opt"><input class="radio-altitude__input" type="radio" name="radio-altitude" checked="" value="base"/>Base</label>
<label class="radio-altitude__opt"><input class="radio-altitude__input" type="radio" name="radio-altitude" value="camp"/>Camp</label>
<label class="radio-altitude__opt"><input class="radio-altitude__input" type="radio" name="radio-altitude" value="summit"/>Summit</label>
</div>
</div>.radio-altitude { --radio-altitude-p: 0; --radio-altitude-k: 0; display: grid; justify-items: center; gap: 12px; }
.radio-altitude:has(.radio-altitude__input[value='camp']:checked) { --radio-altitude-p: 0.55; --radio-altitude-k: 1; }
.radio-altitude:has(.radio-altitude__input[value='summit']:checked) { --radio-altitude-p: 1; --radio-altitude-k: 2; }
.radio-altitude__map { position: relative; width: 200px; height: 100px; }
.radio-altitude__map svg { position: absolute; inset: 0; width: 200px; height: 100px; }
.radio-altitude__range { fill: light-dark(#ebedf0, #232529); }
.radio-altitude__peak { fill: light-dark(#dbdde1, #2e3035); }
.radio-altitude__snow { fill: light-dark(#50535b, #c6c8cd); }
.radio-altitude__trail { fill: none; stroke: light-dark(#6d7179, #7d8087); stroke-width: 1.4; stroke-dasharray: 2 3; stroke-linecap: round; }
.radio-altitude__walked {
fill: none;
stroke: light-dark(#373a40, #f1f2f3);
stroke-width: 2;
stroke-linecap: round;
stroke-linejoin: round;
stroke-dasharray: 1;
stroke-dashoffset: calc(1 - var(--radio-altitude-p));
transition: stroke-dashoffset 1.1s cubic-bezier(0.45, 0, 0.3, 1);
}
.radio-altitude__climber {
position: absolute;
left: 0;
top: 0;
width: 10px;
height: 10px;
border-radius: 50%;
background: light-dark(#373a40, #f1f2f3);
box-shadow: 0 0 0 3px color-mix(in oklab, light-dark(#373a40, #f1f2f3) 25%, transparent);
offset-path: path('M20 92L60 80L44 66L86 54L70 40L104 28L120 12');
offset-rotate: 0deg;
offset-distance: calc(var(--radio-altitude-p) * 100%);
transition: offset-distance 1.1s cubic-bezier(0.45, 0, 0.3, 1);
}
.radio-altitude__readout { position: absolute; right: 0; top: 0; height: 16px; overflow: hidden; }
.radio-altitude__strip { display: grid; transform: translateY(calc(var(--radio-altitude-k) * -16px)); transition: transform 0.5s cubic-bezier(0.3, 1.3, 0.5, 1) 0.4s; }
.radio-altitude__strip span { height: 16px; color: light-dark(#42454c, #e5e6e9); font-size: 11px; font-weight: 600; line-height: 16px; text-align: right; font-variant-numeric: tabular-nums; }
.radio-altitude__opts { display: flex; gap: 4px; padding: 4px; border-radius: 10px; background: light-dark(#f3f4f7, #1a1c1f); box-shadow: inset 0 0 0 1px light-dark(#dbdde1, #2e3035); }
.radio-altitude__opt {
position: relative;
padding: 5px 12px;
border-radius: 7px;
color: light-dark(#5f626a, #a7abb2);
font-size: 12px;
font-weight: 600;
cursor: pointer;
transition: color 0.2s, background-color 0.2s;
}
.radio-altitude__opt:hover { color: light-dark(#42454c, #e5e6e9); }
.radio-altitude__input { position: absolute; width: 1px; height: 1px; margin: 0; opacity: 0; }
.radio-altitude__opt:has(.radio-altitude__input:focus-visible) { outline: 2px solid light-dark(#5f626a, #a7abb2); outline-offset: 2px; }
.radio-altitude__opt:has(.radio-altitude__input:checked) { background: light-dark(#42454c, #e5e6e9); color: light-dark(#fbfcfd, #121417); }
@media (prefers-reduced-motion: reduce) {
.radio-altitude * { transition-duration: 0.01s !important; transition-delay: 0s !important; }
}Goal: Create a "Altitude" radio.
Visual behavior: Waypoints on a mountain: choose base, camp or summit and the climber follows the zigzag trail up or down to it, the walked trail drawing behind them, and the altitude rolls.
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 climber moves along the trail with offset-path and offset-distance, and the walked part is the same path drawn with stroke-dashoffset; both read one progress variable, so they stay together.
- 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 climber jumps to the waypoint.
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 "Altitude" radio.
Visual behavior: Waypoints on a mountain: choose base, camp or summit and the climber follows the zigzag trail up or down to it, the walked trail drawing behind them, and the altitude rolls.
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 climber moves along the trail with offset-path and offset-distance, and the walked part is the same path drawn with stroke-dashoffset; both read one progress variable, so they stay together.
- 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 climber jumps to the waypoint.
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
Waypoints on a mountain: choose base, camp or summit and the climber follows the zigzag trail up or down to it, the walked trail drawing behind them, and the altitude rolls.
- Dependencies
- None
- Difficulty
- Intermediate
- Triggers
- click, state change, draw
- Techniques
- css variables, css transition, stroke dashoffset, svg
- 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 climber jumps to the waypoint.