How a rolling number counter works, and how to build one in React

November 14, 2026 · 7 min read

Counters that tick up when a number changes, like a follower count or a price, draw the eye and communicate change better than a number that just swaps. The classic version rolls each digit vertically, like an old odometer. It looks like a complicated effect, but it comes down to one simple idea: every digit is a tall strip with the numbers 0 to 9 stacked on top of each other, and you slide the strip to show the right one.

The digit strip

Imagine a window exactly one digit tall. Behind it is a column containing 0, 1, 2 up to 9, each one line high. To show a 3, you shift the column up by three lines. To change from 3 to 7, you animate the shift from three lines to seven. The window hides everything else with overflow hidden.

digit.tsx
import { motion } from "motion/react"

const digits = [0, 1, 2, 3, 4, 5, 6, 7, 8, 9]

function Digit({ value }: { value: number }) {
  return (
    <span className="relative inline-block h-[1em] overflow-hidden leading-none">
      <motion.span
        className="flex flex-col"
        animate={{ y: -value + "em" }}
        transition={{ type: "spring", stiffness: 300, damping: 30 }}
      >
        {digits.map((d) => (
          <span key={d} className="h-[1em] leading-none">{d}</span>
        ))}
      </motion.span>
    </span>
  )
}

Because each line is exactly 1em tall, shifting by -value em lands precisely on the right digit, whatever the font size. A spring gives the roll a natural start and a soft landing.

Use tabular figures

In many fonts the digit 1 is narrower than the digit 8. If your digits have different widths the number will jitter sideways as it changes. Add the tabular-nums utility (font-variant-numeric: tabular-nums), which makes every digit the same width and keeps the layout stable.

Splitting a number into digits

Convert the number to a string, split it into characters, and render a Digit for each numeric character. Anything that is not a digit, such as a comma or a decimal point, is rendered as plain text. Using Intl.NumberFormat to produce the string gives you correct grouping for the user's locale for free.

roll.tsx
export function NumberRoll({ value }: { value: number }) {
  const text = new Intl.NumberFormat("en-US").format(value)
  const chars = text.split("")

  return (
    <span aria-label={text} role="img" className="inline-flex tabular-nums">
      {chars.map((c, i) => {
        // key by place value from the right so digits keep their identity
        const key = chars.length - i
        return /\d/.test(c) ? (
          <span key={key} aria-hidden><Digit value={Number(c)} /></span>
        ) : (
          <span key={key} aria-hidden>{c}</span>
        )
      })}
    </span>
  )
}

Keep digits stable when the length changes

When a number grows from 999 to 1,000, a naive implementation re-creates every digit, because the keys are based on index from the left. The fix is to key by position from the right: the ones digit is always key 1, the tens digit is always key 2, and so on. Existing digits keep their identity and simply roll to new values, and only the new leading digit mounts.

Do not forget screen readers

A column of stacked digits is meaningless to assistive technology: it would read out 0123456789 for every digit. Hide the strips with aria-hidden and put the real value in an aria-label on the wrapper, as in the example above. Now a screen reader announces "1,000" once, and sighted users get the animation.

If the number changes often, such as a live counter, consider an aria-live region that announces updates politely and not on every tick.

Reduced motion

Rolling digits are a motion effect, so when the user prefers reduced motion, jump straight to the final value. With Motion, useReducedMotion lets you set the transition duration to zero for those users.

The Number Roll component on makeui includes all of this, so you can drop it in or use it as a reference for your own.

Related component

Number Roll

An odometer-style animated number for React. Each digit scrolls to its value, perfect for counters and stats.

See the component

More guides