Skip to content

Count Up

A number that counts up when it first comes into view, pauses off-screen and never starts over.

$npx shadcn@latest add https://framebrick.co/r/count-up.json

From the Tustel template, see it in context.

Years of experience
80+
Projects completed
120+
Happy clients
45+
Awards received
18

Examples

Formatted, over a set time

A big number takes as long as a small one with `duration`, and `format` adds the separators.

12,400

Visitors this month

<CountUp value={12400} duration={1.6} format={{ useGrouping: true }} className="text-5xl font-semibold" />

A decimal

A rating counts 0.0, 0.1 … 4.9 by the decimals it has, and the digits keep their fraction.

4.9

Average rating from 2,400 reviews

<CountUp value={4.9} className="text-5xl font-semibold" />

// the step can be set: 0 → 5 in halves
<CountUp value={5} step={0.5} />

Installation

$ npx shadcn@latest add https://framebrick.co/r/count-up.json

Usage

import { CountUp } from "@/components/ui/count-up";

<p className="text-5xl font-semibold">
  <CountUp value={120} from={40} />+
</p>

// a four-digit figure: a fixed time instead of Framer's rate, and separators
<CountUp value={12400} duration={1.6} format={{ useGrouping: true }} />

// a decimal counts by the decimals it has: 0.0, 0.1 … 4.9
<CountUp value={4.9} />

Props

PropTypeDefaultDescription
valuenumber—Where it ends.
fromnumber0Where it starts.
stepnumber1, or 0.1 for one decimalThe size of a step, above 0. Left out, it follows the decimals `value` and `from` have: 4.9 counts by 0.1 (49 steps), 4.95 by 0.01, whole numbers by 1. The digits keep the step's fraction (0.0, 0.1 …) unless `format` sets the fraction digits.
intervalnumber5Milliseconds per step, as in Framer: +1 every 5 ms, so 0 → 80 takes 0.4 s, and 0 → 4.9 by 0.1 takes 0.25 s.
durationnumber—Total time in seconds, instead of the rate: a big number then takes as long as a small one.
formatIntl.NumberFormatOptions—Formatting, e.g. { useGrouping: true } or { notation: "compact" }. Plain digits by default, as in Framer.
localestring"en-US"Locale for `format`. Always explicit, so the server and the browser agree on the digits.
classNamestring—Classes for the number: its size, weight and colour.
  • It counts once its first pixel is in view, carries on from where it was after being off-screen, and never starts over.
  • It counts by time, not with a timer per step: a 5 ms interval is clamped and throttled by the browser, a clock is not. The digits are tabular, so the width does not jitter while they change.
  • The final number is always in the page, in a second element. Screen readers read it (the moving digits are aria-hidden, so 41, 42, 43 are never announced), and it is what shows with reduced motion, in print and without JavaScript. CSS swaps the two, so the markup never depends on reduced motion.
  • Framer's rate suits small numbers: 80 takes 0.4 s, 12 000 would take a minute. Give big ones a `duration`.
  • A decimal counts by the decimals it has, as Framer's Number counter does with a decimal: a 4.9 rating runs 0.0, 0.1 … 4.9 in 49 steps and keeps the one fraction digit all the way, so the width does not jump when it passes 3.0. Rounding every frame to a whole number would show 0 … 5 and then jump to 4.9.
  • `step` sets the size of a step and the rate with it (distance ÷ step × `interval`). A step that does not divide the distance evenly never carries the number past `value`: the last frame sets `value` itself.
  • For tests: with JavaScript on, the element's textContent holds the moving digits and the final number together. Query by role and name, or read the final element (data-count-up-final).

AI prompt

Paste into v0, Lovable, Bolt or Claude to rebuild this component in your own project.

Create a React + Tailwind CSS component called CountUp (no animation library).
- Props: value, from (0), step (the size of a step, above 0; when missing, 10 ** -d where d is the larger count of
  decimals that value and from are written with, so 4.9 counts by 0.1 and whole numbers by 1), interval (5 —
  milliseconds per step, as in Framer), duration (seconds; replaces the rate), format (Intl.NumberFormat options; plain
  digits when absent), locale ("en-US", always explicit so the server and the browser agree).
- Count by time, not with a timer per step: keep the elapsed milliseconds in a closure, advance it by the frame's delta in
  requestAnimationFrame, and put the progress (0 to 1) in state. With steps = |value - from| / step (cleaned with
  toFixed(6)), the shown number is from ± step * min(floor(steps), round(steps * progress)), rounded to the step's
  decimals with +x.toFixed(decimals); at progress 1 it is exactly value. The total time is steps * interval, or
  duration * 1000.
- Digits: whole numbers print with String(n). With decimals, print through Intl.NumberFormat with minimumFractionDigits and
  maximumFractionDigits = the step's decimals (and useGrouping false when there is no format), unless format itself sets
  a fraction digit option, so 3.0 keeps its zero and the width does not jump. Draw the final number the same way.
- An IntersectionObserver on the element starts the frame loop when any part of it is on screen and cancels it when it
  leaves. The elapsed time is kept, so it carries on from where it was and never starts over.
- Render two spans inside one span with tabular-nums: the moving digits (aria-hidden, print:hidden, motion-reduce:hidden)
  and the final number (sr-only, print:not-sr-only, motion-reduce:not-sr-only). Add a <noscript><style> that hides the
  moving digits and shows the final number, so a page without JavaScript shows the real value, not the start.
- Do not start the loop when matchMedia("(prefers-reduced-motion: reduce)") matches — read it inside the effect, never
  while rendering: the markup must not depend on it, because the server cannot know it.

Be the first to know

Get new templates and components first

One short email when we release a template or a free component. No spam — unsubscribe anytime.

We use your email only for Framebrick updates. Privacy policy