Odometer Pricing Free React component
Pricing cards with a monthly / yearly switch. Flip it and every price rolls to its new value digit by digit, like an odometer, with a sliding pill on the switch. Includes a standalone RollingNumber you can use for any counter.
Get the code
npx shadcn@latest add https://alphenex.com/r/odometer-pricing.jsonWorks with any React project through the shadcn CLI. Prefer to paste it yourself? Copy the two files below into components/alphenex/. No Tailwind or animation library needed.
import OdometerPricing from '@/components/alphenex/odometer-pricing';
<OdometerPricing />'use client';
import { useId, useState } from 'react';
import './odometer-pricing.css';
const DEFAULT_PLANS = [
{ name: 'Starter', monthly: 29, features: ['1 website', 'Basic analytics', 'Email support'] },
{ name: 'Growth', monthly: 79, features: ['5 websites', 'SEO toolkit', 'Priority support'], featured: true },
{ name: 'Studio', monthly: 199, features: ['Unlimited sites', 'Team seats', 'Dedicated manager'] },
];
/**
* RollingNumber
* A number whose digits roll like an odometer when it changes. Digits are
* matched from the right, so 79 → 63 rolls each column on its own.
*/
export function RollingNumber({ value, duration = 900, className = '' }) {
const digits = String(Math.max(0, Math.round(value))).split('');
return (
<span className={`alx-roll ${className}`} aria-hidden="true">
{digits.map((digit, i) => {
const fromRight = digits.length - 1 - i;
return (
<span className="alx-roll__digit" key={`d${fromRight}`}>
<span
className="alx-roll__column"
style={{
transform: `translateY(${-Number(digit) * 10}%)`,
transitionDuration: `${duration}ms`,
transitionDelay: `${fromRight * 70}ms`,
}}
>
{'0123456789'.split('').map((n) => (
<span key={n}>{n}</span>
))}
</span>
</span>
);
})}
</span>
);
}
/**
* OdometerPricing
* Pricing cards with a monthly / yearly switch. When it flips, every price
* rolls to its new value digit by digit.
*
* Free from Alphenex Lab: https://alphenex.com/lab/odometer-pricing (MIT)
*/
export default function OdometerPricing({
plans = DEFAULT_PLANS,
yearlyDiscount = 20, // % off when billed yearly
currency = '$',
accent = '#0a8fd0',
duration = 900, // roll time in ms
ctaLabel = 'Get started',
onSelect,
className = '',
style,
...props
}) {
const [yearly, setYearly] = useState(false);
const labelId = useId();
const priceFor = (plan) => (yearly ? Math.round(plan.monthly * (1 - yearlyDiscount / 100)) : plan.monthly);
return (
<div className={`alx-pricing ${className}`} style={{ '--alx-price-accent': accent, ...style }} {...props}>
<div className="alx-pricing__switch" role="radiogroup" aria-labelledby={labelId}>
<span id={labelId} className="alx-pricing__sr">Billing period</span>
<span className={`alx-pricing__pill ${yearly ? 'is-yearly' : ''}`} aria-hidden="true" />
<button type="button" role="radio" aria-checked={!yearly} onClick={() => setYearly(false)}>
Monthly
</button>
<button type="button" role="radio" aria-checked={yearly} onClick={() => setYearly(true)}>
Yearly <em>−{yearlyDiscount}%</em>
</button>
</div>
<div className="alx-pricing__plans">
{plans.map((plan) => {
const price = priceFor(plan);
return (
<article key={plan.name} className={`alx-pricing__plan ${plan.featured ? 'is-featured' : ''}`}>
<h3>{plan.name}</h3>
<p className="alx-pricing__price">
<span className="alx-pricing__sr">{`${currency}${price} per month${yearly ? ', billed yearly' : ''}`}</span>
<span className="alx-pricing__currency" aria-hidden="true">{currency}</span>
<RollingNumber value={price} duration={duration} />
<span className="alx-pricing__per" aria-hidden="true">/mo</span>
</p>
<ul>
{plan.features.map((feature) => (
<li key={feature}>{feature}</li>
))}
</ul>
<button type="button" className="alx-pricing__cta" onClick={() => onSelect?.(plan, yearly)}>
{ctaLabel}
</button>
</article>
);
})}
</div>
</div>
);
}
/* OdometerPricing, Alphenex Lab (MIT) */
.alx-pricing {
--alx-price-accent: #0a8fd0;
display: grid;
justify-items: center;
gap: 1.75rem;
color: #111418;
}
.alx-pricing__sr {
position: absolute;
width: 1px;
height: 1px;
overflow: hidden;
clip: rect(0 0 0 0);
white-space: nowrap;
}
/* Monthly / yearly switch with a sliding pill behind the active option. */
.alx-pricing__switch {
position: relative;
display: inline-grid;
grid-template-columns: 1fr 1fr;
padding: 4px;
border-radius: 999px;
background: #eef0f2;
}
.alx-pricing__switch button {
position: relative;
z-index: 1;
padding: 0.6rem 1.2rem;
border: 0;
background: none;
color: #676d75;
font: inherit;
font-size: 0.9rem;
font-weight: 600;
cursor: pointer;
transition: color 0.3s ease;
}
.alx-pricing__switch button[aria-checked='true'] {
color: #111418;
}
.alx-pricing__switch em {
margin-left: 0.25rem;
color: var(--alx-price-accent);
font-style: normal;
}
.alx-pricing__pill {
position: absolute;
top: 4px;
bottom: 4px;
left: 4px;
width: calc(50% - 4px);
border-radius: 999px;
background: #fff;
box-shadow: 0 2px 10px rgba(17, 20, 24, 0.12);
transition: transform 0.45s cubic-bezier(0.2, 0.8, 0.2, 1);
}
.alx-pricing__pill.is-yearly {
transform: translateX(100%);
}
.alx-pricing__plans {
display: grid;
grid-template-columns: repeat(auto-fit, minmax(190px, 1fr));
gap: 1rem;
width: 100%;
}
.alx-pricing__plan {
display: flex;
flex-direction: column;
gap: 0.9rem;
padding: 1.5rem;
border: 1px solid rgba(17, 20, 24, 0.08);
border-radius: 20px;
background: #fff;
}
.alx-pricing__plan.is-featured {
border-color: var(--alx-price-accent);
box-shadow: 0 14px 40px -18px var(--alx-price-accent);
}
.alx-pricing__plan h3 {
margin: 0;
font-size: 1rem;
font-weight: 600;
}
.alx-pricing__price {
display: flex;
align-items: baseline;
margin: 0;
font-size: 2.6rem;
font-weight: 800;
letter-spacing: -0.04em;
line-height: 1;
font-variant-numeric: tabular-nums;
}
.alx-pricing__currency {
font-size: 0.55em;
align-self: flex-start;
margin-top: 0.15em;
}
.alx-pricing__per {
margin-left: 0.2rem;
color: #676d75;
font-size: 0.35em;
font-weight: 500;
letter-spacing: 0;
}
.alx-pricing__plan ul {
display: grid;
gap: 0.4rem;
margin: 0;
padding: 0;
list-style: none;
color: #676d75;
font-size: 0.9rem;
}
.alx-pricing__plan li::before {
content: '✓';
margin-right: 0.5rem;
color: var(--alx-price-accent);
font-weight: 700;
}
.alx-pricing__cta {
margin-top: auto;
padding: 0.75rem 1rem;
border: 0;
border-radius: 999px;
background: #111418;
color: #fff;
font: inherit;
font-weight: 600;
cursor: pointer;
}
.is-featured .alx-pricing__cta {
background: var(--alx-price-accent);
}
/* The odometer: each digit is a 0–9 column slid up behind a 1em window. */
.alx-roll {
display: inline-flex;
}
.alx-roll__digit {
display: inline-block;
height: 1em;
overflow: hidden;
line-height: 1;
}
.alx-roll__column {
display: flex;
flex-direction: column;
transition-property: transform;
transition-timing-function: cubic-bezier(0.2, 0.9, 0.25, 1.15);
}
.alx-roll__column span {
display: block;
height: 1em;
}
@media (prefers-reduced-motion: reduce) {
.alx-roll__column,
.alx-pricing__pill {
transition: none !important;
}
}
Paste this into Claude, ChatGPT, Cursor, Lovable or v0 to build it from scratch.
Build a React "OdometerPricing" component with plain CSS. A monthly / yearly switch (two radio buttons with a white pill that slides behind the active one) controls the prices on three plan cards; yearly applies a yearlyDiscount percentage. Every price is a "RollingNumber": each digit is a 1em-tall window with overflow hidden holding a vertical column of 0–9, moved with translateY(-digit × 10%) and a CSS transition with a slight overshoot easing. Match digits from the right with keys so each column rolls on its own, and stagger the delay by 70ms per column. Give the real price to screen readers in a visually hidden span. Props: plans, yearlyDiscount, currency, accent, duration, ctaLabel, onSelect.How the odometer pricing works
Each digit is a small window, exactly one character tall, with overflow hidden. Inside it sits a column of the digits 0 to 9. Showing a 7 means sliding the column up by seven tenths of its height, and a CSS transition turns that jump into the rolling motion.
Digits are keyed from the right, so when 79 becomes 63 the ones column and the tens column each roll on their own, with a short stagger between them. A slight overshoot in the easing makes them settle like a mechanical counter.
The rolling digits are hidden from screen readers. A visually hidden line reads out the real price, such as "$63 per month, billed yearly".
Frequently asked questions
Want motion like this on your website?
We design and build custom websites with motion, 3D and SEO built in. Websites from $500.