Odometer
import { useState } from 'react';
const DIGITS = [0, 1, 2, 3, 4, 5, 6, 7, 8, 9];
const css = `
.slider-odometer { display: grid; justify-items: center; gap: 16px; width: 220px; }
.slider-odometer__read { display: flex; align-items: center; padding: 6px 10px; border-radius: 10px; background: light-dark(#f3f4f7, #1a1c1f); box-shadow: inset 0 0 0 1px light-dark(#ebedf0, #232529), inset 0 6px 10px -6px light-dark(rgba(0, 0, 0, 0.15), rgba(0, 0, 0, 0.5)); color: light-dark(#373a40, #f1f2f3); font-size: 30px; font-weight: 600; font-variant-numeric: tabular-nums; line-height: 1; }
.slider-odometer__sym { color: light-dark(#5f626a, #a7abb2); font-size: 22px; margin-right: 3px; }
.slider-odometer__drum { position: relative; height: 1em; width: 0.62em; overflow: hidden; transition: width 0.35s cubic-bezier(0.3, 1.2, 0.5, 1), opacity 0.25s; -webkit-mask: linear-gradient(transparent, #000 25%, #000 75%, transparent); mask: linear-gradient(transparent, #000 25%, #000 75%, transparent); }
.slider-odometer__reel { position: absolute; left: 0; top: 0; display: grid; transform: translateY(calc(var(--d) * -1em)); transition: transform 0.6s cubic-bezier(0.3, 1.3, 0.5, 1); transition-delay: var(--delay); }
.slider-odometer__reel span { height: 1em; text-align: center; }
.slider-odometer__comma { display: inline-block; width: 0.3em; overflow: hidden; color: light-dark(#5f626a, #a7abb2); transition: width 0.35s, opacity 0.25s; }
.slider-odometer__drum[data-lead], .slider-odometer__comma[data-lead] { width: 0; opacity: 0; }
.slider-odometer__track { position: relative; width: 100%; height: 24px; }
.slider-odometer__rail { position: absolute; left: 0; right: 0; top: 10px; height: 4px; border-radius: 2px; background: light-dark(#ebedf0, #232529); }
.slider-odometer__fill { position: absolute; left: 0; top: 10px; height: 4px; border-radius: 2px; width: calc(9px + var(--slider-odometer-v) * (100% - 18px)); background: light-dark(#50535b, #c6c8cd); }
.slider-odometer__thumb { position: absolute; top: 3px; left: calc(var(--slider-odometer-v) * (100% - 18px)); width: 18px; height: 18px; border-radius: 50%; background: light-dark(#373a40, #f1f2f3); box-shadow: 0 2px 6px light-dark(rgba(0, 0, 0, 0.12), rgba(0, 0, 0, 0.4)); }
.slider-odometer:has(.slider-odometer__input:focus-visible) .slider-odometer__thumb { outline: 2px solid light-dark(#50535b, #c6c8cd); outline-offset: 3px; }
.slider-odometer__input { position: absolute; inset: 0; width: 100%; height: 100%; margin: 0; opacity: 0; cursor: pointer; -webkit-appearance: none; appearance: none; background: none; }
.slider-odometer__input::-webkit-slider-thumb { -webkit-appearance: none; width: 18px; height: 18px; }
.slider-odometer__input::-moz-range-thumb { width: 18px; height: 18px; border: 0; }
@media (prefers-reduced-motion: reduce) {
.slider-odometer__reel, .slider-odometer__drum, .slider-odometer__comma { transition: none; }
}
`;
export function OdometerSlider() {
const [amount, setAmount] = useState(2450);
const digits = String(amount).padStart(4, '0').split('').map(Number);
// Leading zeros fold away, so $450 never reads $0,450; the ones digit always stays.
const lead = 4 - String(amount).length;
return (
<>
<style>
{css}
</style>
<div className="slider-odometer" style={{ '--slider-odometer-v': amount / 5000 } as React.CSSProperties}>
<span className="slider-odometer__read" aria-hidden="true">
<span className="slider-odometer__sym">$</span>
{digits.map((d, i) => (
<span key={i} style={{ display: 'contents' }}>
{i === 1 && (
<span className="slider-odometer__comma" data-lead={lead >= 1 ? '' : undefined}>
,
</span>
)}
<span className="slider-odometer__drum" data-lead={i < lead ? '' : undefined}>
<span className="slider-odometer__reel" style={{ '--d': d, '--delay': `${(3 - i) * 40}ms` } as React.CSSProperties}>
{DIGITS.map((n) => (
<span key={n}>{n}</span>
))}
</span>
</span>
</span>
))}
</span>
<div className="slider-odometer__track">
<span className="slider-odometer__rail" />
<span className="slider-odometer__fill" />
<span className="slider-odometer__thumb" />
<input
className="slider-odometer__input"
type="range"
min={0}
max={5000}
step={50}
value={amount}
onChange={(e) => setAmount(+e.target.value)}
aria-label="Budget"
aria-valuetext={`${amount} dollars`}
/>
</div>
</div>
</>
);
}Markup where the component goes, CSS in your stylesheet, script before </body>. In Vue, Svelte or Angular, call initSliderOdometer(el) on the mounted element instead.
<div class="slider-odometer" style="--slider-odometer-v:0.49">
<span class="slider-odometer__read" aria-hidden="true">
<span class="slider-odometer__sym">$</span>
<span style="display:contents">
<span class="slider-odometer__drum">
<span class="slider-odometer__reel" style="--d:2;--delay:120ms">
<span>0</span>
<span>1</span>
<span>2</span>
<span>3</span>
<span>4</span>
<span>5</span>
<span>6</span>
<span>7</span>
<span>8</span>
<span>9</span>
</span>
</span>
</span>
<span style="display:contents">
<span class="slider-odometer__comma">,</span>
<span class="slider-odometer__drum">
<span class="slider-odometer__reel" style="--d:4;--delay:80ms">
<span>0</span>
<span>1</span>
<span>2</span>
<span>3</span>
<span>4</span>
<span>5</span>
<span>6</span>
<span>7</span>
<span>8</span>
<span>9</span>
</span>
</span>
</span>
<span style="display:contents">
<span class="slider-odometer__drum">
<span class="slider-odometer__reel" style="--d:5;--delay:40ms">
<span>0</span>
<span>1</span>
<span>2</span>
<span>3</span>
<span>4</span>
<span>5</span>
<span>6</span>
<span>7</span>
<span>8</span>
<span>9</span>
</span>
</span>
</span>
<span style="display:contents">
<span class="slider-odometer__drum">
<span class="slider-odometer__reel" style="--d:0;--delay:0ms">
<span>0</span>
<span>1</span>
<span>2</span>
<span>3</span>
<span>4</span>
<span>5</span>
<span>6</span>
<span>7</span>
<span>8</span>
<span>9</span>
</span>
</span>
</span>
</span>
<div class="slider-odometer__track">
<span class="slider-odometer__rail"></span>
<span class="slider-odometer__fill"></span>
<span class="slider-odometer__thumb"></span>
<input class="slider-odometer__input" type="range" min="0" max="5000" step="50" aria-label="Budget" aria-valuetext="2450 dollars" value="2450"/>
</div>
</div>.slider-odometer { display: grid; justify-items: center; gap: 16px; width: 220px; }
.slider-odometer__read { display: flex; align-items: center; padding: 6px 10px; border-radius: 10px; background: light-dark(#f3f4f7, #1a1c1f); box-shadow: inset 0 0 0 1px light-dark(#ebedf0, #232529), inset 0 6px 10px -6px light-dark(rgba(0, 0, 0, 0.15), rgba(0, 0, 0, 0.5)); color: light-dark(#373a40, #f1f2f3); font-size: 30px; font-weight: 600; font-variant-numeric: tabular-nums; line-height: 1; }
.slider-odometer__sym { color: light-dark(#5f626a, #a7abb2); font-size: 22px; margin-right: 3px; }
.slider-odometer__drum { position: relative; height: 1em; width: 0.62em; overflow: hidden; transition: width 0.35s cubic-bezier(0.3, 1.2, 0.5, 1), opacity 0.25s; -webkit-mask: linear-gradient(transparent, #000 25%, #000 75%, transparent); mask: linear-gradient(transparent, #000 25%, #000 75%, transparent); }
.slider-odometer__reel { position: absolute; left: 0; top: 0; display: grid; transform: translateY(calc(var(--d) * -1em)); transition: transform 0.6s cubic-bezier(0.3, 1.3, 0.5, 1); transition-delay: var(--delay); }
.slider-odometer__reel span { height: 1em; text-align: center; }
.slider-odometer__comma { display: inline-block; width: 0.3em; overflow: hidden; color: light-dark(#5f626a, #a7abb2); transition: width 0.35s, opacity 0.25s; }
.slider-odometer__drum[data-lead], .slider-odometer__comma[data-lead] { width: 0; opacity: 0; }
.slider-odometer__track { position: relative; width: 100%; height: 24px; }
.slider-odometer__rail { position: absolute; left: 0; right: 0; top: 10px; height: 4px; border-radius: 2px; background: light-dark(#ebedf0, #232529); }
.slider-odometer__fill { position: absolute; left: 0; top: 10px; height: 4px; border-radius: 2px; width: calc(9px + var(--slider-odometer-v) * (100% - 18px)); background: light-dark(#50535b, #c6c8cd); }
.slider-odometer__thumb { position: absolute; top: 3px; left: calc(var(--slider-odometer-v) * (100% - 18px)); width: 18px; height: 18px; border-radius: 50%; background: light-dark(#373a40, #f1f2f3); box-shadow: 0 2px 6px light-dark(rgba(0, 0, 0, 0.12), rgba(0, 0, 0, 0.4)); }
.slider-odometer:has(.slider-odometer__input:focus-visible) .slider-odometer__thumb { outline: 2px solid light-dark(#50535b, #c6c8cd); outline-offset: 3px; }
.slider-odometer__input { position: absolute; inset: 0; width: 100%; height: 100%; margin: 0; opacity: 0; cursor: pointer; -webkit-appearance: none; appearance: none; background: none; }
.slider-odometer__input::-webkit-slider-thumb { -webkit-appearance: none; width: 18px; height: 18px; }
.slider-odometer__input::-moz-range-thumb { width: 18px; height: 18px; border: 0; }
@media (prefers-reduced-motion: reduce) {
.slider-odometer__reel, .slider-odometer__drum, .slider-odometer__comma { transition: none; }
}function initSliderOdometer(root) {
var input = root.querySelector('.slider-odometer__input');
var drums = root.querySelectorAll('.slider-odometer__drum');
var reels = root.querySelectorAll('.slider-odometer__reel');
var comma = root.querySelector('.slider-odometer__comma');
function update() {
var amount = +input.value;
var text = String(amount);
var digits = ('0000' + text).slice(-4);
// Leading zeros fold away, so $450 never reads $0,450; the ones digit always stays.
var lead = 4 - text.length;
root.style.setProperty('--slider-odometer-v', amount / 5000);
for (var i = 0; i < 4; i++) {
reels[i].style.setProperty('--d', digits[i]);
drums[i].toggleAttribute('data-lead', i < lead);
}
comma.toggleAttribute('data-lead', lead >= 1);
input.setAttribute('aria-valuetext', amount + ' dollars');
}
input.addEventListener('input', update);
update();
return function () { input.removeEventListener('input', update); };
}
document.querySelectorAll('.slider-odometer').forEach(initSliderOdometer);Goal: Create a "Odometer" slider.
Visual behavior: A budget slider with an odometer: each digit of the amount rolls on its own drum to the new value, a beat apart, and leading zeros fold away.
Technique:
- A real <input type="range"> lies over the drawing, transparent (opacity 0, appearance none), with its thumb hit area sized to the drawn thumb, so dragging, clicking the track and the arrow, Page Up/Down, Home and End keys all work natively. The drawing is aria-hidden.
- Each digit is a column of 0 to 9 in a masked window, translated by its digit (a CSS custom property) with a delay that grows towards the left, so the ones digit moves first.
- Leading drums and the comma collapse to zero width with a data-lead attribute, so $450 never reads $0,450.
- :has(input:focus-visible) outlines the drawn thumb, so keyboard focus is visible though the input itself is not.
Accessibility: A native range input with an aria-label and an aria-valuetext in words, so a screen reader announces the reading rather than a bare number; keyboard focus outlines the drawn thumb. Under prefers-reduced-motion the digits change without rolling.
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 "Odometer" slider.
Visual behavior: A budget slider with an odometer: each digit of the amount rolls on its own drum to the new value, a beat apart, and leading zeros fold away.
Technique:
- A real <input type="range"> lies over the drawing, transparent (opacity 0, appearance none), with its thumb hit area sized to the drawn thumb, so dragging, clicking the track and the arrow, Page Up/Down, Home and End keys all work natively. The drawing is aria-hidden.
- Each digit is a column of 0 to 9 in a masked window, translated by its digit (a CSS custom property) with a delay that grows towards the left, so the ones digit moves first.
- Leading drums and the comma collapse to zero width with a data-lead attribute, so $450 never reads $0,450.
- :has(input:focus-visible) outlines the drawn thumb, so keyboard focus is visible though the input itself is not.
Accessibility: A native range input with an aria-label and an aria-valuetext in words, so a screen reader announces the reading rather than a bare number; keyboard focus outlines the drawn thumb. Under prefers-reduced-motion the digits change without rolling.
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 budget slider with an odometer: each digit of the amount rolls on its own drum to the new value, a beat apart, and leading zeros fold away.
- Dependencies
- None
- Difficulty
- Intermediate
- Triggers
- state change, delay stagger
- Techniques
- css variables, css transition, transition delay stagger
- Reduced motion
- Respected
- Theme
- Light and dark (follows your page's color-scheme)
A native range input with an aria-label and an aria-valuetext in words, so a screen reader announces the reading rather than a bare number; keyboard focus outlines the drawn thumb. Under prefers-reduced-motion the digits change without rolling.