motionkit.byHizmedia (opens hizmedia.com in a new tab)
ComponentsTheme StudioPage BuilderPricing

Start building with motion.

206 animated React components, free to browse and customise. Plus unlocks every premium one, with a 14-day free trial.

Browse componentsSee Plus
motionkit.

Animated React components for people who love the details. Built with TypeScript, Tailwind CSS and Motion.

  • Hizmedia on Instagram (opens in a new tab)
  • Hizmedia on LinkedIn (opens in a new tab)
  • Hizmedia on YouTube (opens in a new tab)

Product

  • Components
  • Theme Studio
  • Page Builder
  • MotionKit Plus
  • What's new

Components

  • Backgrounds
  • Text effects
  • Buttons
  • Cards
  • Sections
  • All 206 components

Resources

  • Guides
  • Free tools
  • Free components
  • For shadcn/ui
  • Liquid glass
  • Hero sections

Company

  • About
  • Cookie policy
  • Your account
  • Hizmedia (opens in a new tab)
  • Start a project

motionkit.

© 2026 Hizmedia (opens hizmedia.com in a new tab)· Designed and built in the UK

RSS Back to top
    1. Guides
    2. Build it

    Build an Animated Number Counter in React That Counts Up on Scroll

    Count numbers up when they scroll into view in React with Motion: smooth formatting with Intl, no layout shift, screen-reader friendly, reduced motion, and a CSS-only version.

    HHizmediaUpdated 14 November 20266 min read
    On this page
    1. 01The counter
    2. 02Why each detail is there
    3. 03Screen readers and reduced motion
    4. 04A CSS-only version

    A number that counts up as it scrolls into view makes a statistic feel earned. Done carelessly, it also re-renders React sixty times a second, jiggles the layout as digits change width, and reads out every intermediate number to screen readers. This guide builds a counter that avoids all three, in about thirty lines.

    01The counter#

    useInView starts the count once the number is on screen (the same trigger as other scroll animations), and Motion's animate function tweens from 0 to the target. Each frame writes the formatted value straight into the DOM, so React doesn't re-render while it counts. It's the same approach the Stats Section and Number Ticker components use:

    count-up.tsx
    "use client";
    
    import { useEffect, useRef } from "react";
    import { animate, useInView, useReducedMotion } from "motion/react";
    
    export function CountUp({ to, decimals = 0, duration = 1.6 }: { to: number; decimals?: number; duration?: number }) {
      const ref = useRef<HTMLSpanElement>(null);
      const inView = useInView(ref, { once: true, amount: 0.6 });
      const reduceMotion = useReducedMotion();
      const format = new Intl.NumberFormat("en-GB", { minimumFractionDigits: decimals, maximumFractionDigits: decimals });
    
      useEffect(() => {
        const element = ref.current;
        if (!element || !inView) return;
        if (reduceMotion) {
          element.textContent = format.format(to);
          return;
        }
        const controls = animate(0, to, {
          duration,
          ease: [0.16, 1, 0.3, 1],
          onUpdate: (value) => (element.textContent = format.format(value)),
        });
        return () => controls.stop();
      }, [inView, reduceMotion, to, duration]);
    
      return (
        <span className="tabular-nums">
          <span className="sr-only">{format.format(to)}</span>
          <span ref={ref} aria-hidden>
            {format.format(0)}
          </span>
        </span>
      );
    }

    02Why each detail is there#

    • Writing to textContent instead of state: a state update every frame re-renders the component and its children; a direct write costs almost nothing.
    • tabular-nums: gives every digit the same width, so the number doesn't jiggle as it counts and the text around it doesn't shift.
    • Intl.NumberFormat: thousands separators and decimals as people expect them in their locale, at every step of the count.
    • An ease-out curve: fast at the start and slow at the end, so the final digits settle where people can read them.
    • once: true: counting again every time it scrolls past quickly becomes irritating.

    03Screen readers and reduced motion#

    A live-updating number would be announced over and over, or not at all. The counter instead gives screen readers the final value once, in a visually hidden span, and hides the animated one. People who ask for reduced motion see the final number straight away, because useReducedMotion skips the count.

    04A CSS-only version#

    Modern browsers can count with CSS alone, by registering a custom property as an integer and animating it into a counter:

    count.css
    @property --num {
      syntax: "<integer>";
      initial-value: 0;
      inherits: false;
    }
    
    .count {
      animation: count-up 2s cubic-bezier(0.16, 1, 0.3, 1) forwards;
      counter-reset: num var(--num);
    }
    
    .count::after {
      content: counter(num);
    }
    
    @keyframes count-up {
      to { --num: 12400; }
    }

    It's neat, but it runs on page load rather than on scroll, can't format thousands separators, and generated content isn't reliably read by screen readers, so the React version is the better choice for real statistics.

    Put it into practice

    Components from this guide

    • Number TickerCounts up to a value with an eased finish when it scrolls into view.
    • OdometerEvery digit rolls on its own wheel to the new value, like a mileage counter, rather than counting up.
    • Stats SectionPlusA row of headline numbers that count up one after another as the section scrolls into view, each with a small trend line drawing itself underneath.
    • KPI CardA headline number that counts up beside a sparkline that draws itself, with a change badge and hover readout.

    Questions

    How do I start a count-up animation when it scrolls into view?+

    Use Motion's useInView on the element with once: true, and start the animation in an effect when it becomes true.

    Why does my animated number make the layout jump?+

    Digits have different widths in most fonts. Add the tabular-nums class (font-variant-numeric: tabular-nums) so every digit is the same width.

    Is a counting number accessible?+

    It can be: give screen readers the final value once in a visually hidden element, hide the animating one with aria-hidden, and skip the animation for people who prefer reduced motion.

    PreviousMigrating from Framer Motion to Motion: What Changes

    On this page

    1. The counter
    2. Why each detail is there
    3. Screen readers and reduced motion
    4. A CSS-only version

    Found this useful? Send it to someone building with motion.

    Keep reading

    All guides
    • Fundamentals·7 min read

      Scroll Animations in React: whileInView, useScroll and IntersectionObserver

      Three ways to animate on scroll in React: reveal with whileInView, follow scroll position with useScroll, or use IntersectionObserver directly.

      Read guide
    • Build it·6 min read

      How to Make a GitHub-Style Contribution Graph in React

      Build a GitHub-style activity heatmap in React: days in week columns, colour levels, month labels, a fill-in animation, keyboard support and GitHub data.

      Read guide
    • Build it·8 min read

      Page Transitions in the Next.js App Router with View Transitions

      Animate between pages in the Next.js App Router with React's ViewTransition: shared element morphs, directional slides, a fixed header and reduced motion, plus when Motion still helps.

      Read guide