Back to NumbersYou are on Scrolling Number.

Scrolling Number

A mechanical number band that scrolls and stops under a highlight.

Available inAvailable in React, Vue, Svelte, Solid, JavaScript· All five frameworks
PrequelUI

Libraries

PrequelUI

Motion

Spring + short tween

Reduced motion

Fade in place
scrolling-number.tsx
Play with the real component, then read the code it ships with.All components
01

Installation

Installing for React·components/prequelui/scrolling-number.tsx

Add the component

npx shadcn@latest add https://prequeluianimate.terravidhal.me/r/scrolling-number.json
npmthe default on every machine

First component? Set up your project first

Frameworks

The live preview is React. Each tab below is the file that ships for that framework, with the same durations, springs and reduced-motion rule.

5 runtimes
scrolling-number.tsx
"use client";

import * as React from "react";
import { motion, type Transition } from "motion/react";
import { cn } from "@/lib/utils";
import { srOnlyStyle, useReduceMotion, useSeen, useTempoTransition } from "./motion";

const bandSpring: Transition = {
  type: "spring",
  stiffness: 90,
  damping: 30,
  restDelta: 0.001,
  restSpeed: 0.01,
};

export type ScrollingNumberProps = Omit<React.ComponentProps<"div">, "children"> & {
  number: number;
  fromNumber?: number;
  step?: number;
  itemsSize?: number;
  sideItemsCount?: number;
  inView?: boolean;
  inViewOnce?: boolean;
  delay?: number;
  transition?: Transition;
  onCompleted?: () => void;
};

export function ScrollingNumber({
  number,
  fromNumber = 0,
  step = 1,
  itemsSize = 30,
  sideItemsCount = 2,
  inView = false,
  inViewOnce = true,
  delay = 0,
  transition,
  onCompleted,
  className,
  ...props
}: ScrollingNumberProps) {
  const ref = React.useRef<HTMLDivElement>(null);
  const seen = useSeen(ref, inView, inViewOnce);
  const reduce = useReduceMotion();
  const spring = useTempoTransition(transition ?? bandSpring);
  const [started, setStarted] = React.useState(false);

  React.useEffect(() => {
    if (!seen) return;
    if (reduce) {
      setStarted(true);
      onCompleted?.();
      return;
    }
    const timer = window.setTimeout(() => setStarted(true), delay);
    return () => window.clearTimeout(timer);
  }, [delay, onCompleted, reduce, seen]);

  const values = React.useMemo(() => {
    const size = Math.max(1, step);
    const from = Math.round(fromNumber / size) * size;
    const to = Math.round(number / size) * size;
    const direction = to >= from ? 1 : -1;
    const count = Math.abs(Math.round((to - from) / size)) + 1;
    return Array.from({ length: count }, (_, index) => from + index * size * direction);
  }, [fromNumber, number, step]);

  const targetIndex = values.length - 1;
  const height = itemsSize * (1 + sideItemsCount * 2);
  const initialY = sideItemsCount * itemsSize;
  const finalY = (sideItemsCount - targetIndex) * itemsSize;

  return (
    <div
      ref={ref}
      data-slot="scrolling-number"
      className={cn(
        "relative isolate inline-block overflow-hidden rounded-lg [mask-image:linear-gradient(to_bottom,transparent,black_24%,black_76%,transparent)]",
        className,
      )}
      style={{ height }}
      {...props}
    >
      <div
        aria-hidden="true"
        className="pointer-events-none absolute inset-x-1 top-1/2 z-10 -translate-y-1/2 rounded-md border bg-foreground/[0.06] dark:bg-background/20"
        style={{ height: itemsSize }}
      />
      <motion.div
        aria-hidden="true"
        animate={{ y: started ? finalY : initialY }}
        transition={reduce ? { duration: 0 } : spring}
        onAnimationComplete={() => {
          if (started) onCompleted?.();
        }}
        className="relative flex flex-col"
      >
        {values.map((value) => (
          <div
            key={value}
            className={cn(
              "flex shrink-0 items-center justify-center font-medium tabular-nums",
              value === number ? "text-foreground" : "text-muted-foreground/50",
            )}
            style={{ height: itemsSize }}
          >
            {value.toLocaleString("en-US")}
          </div>
        ))}
      </motion.div>
      <span className="sr-only" style={srOnlyStyle()}>
        {number.toLocaleString("en-US")}
      </span>
    </div>
  );
}

Install

npx shadcn@latest add https://prequeluianimate.terravidhal.me/r/scrolling-number.json
npmthe default on every machine

Dependencies

motion lucide-react

The registry keeps the component source, its motion tokens and the reduced-motion branch together, so the install never pulls a different animation from the preview.

02

Usage

Import the component and compose it exactly like the primitive it wraps. Motion is enabled by default; the tempo prop scales every duration and softens every spring.

scrolling-number.tsx
import { ScrollingNumber } from "@/components/prequelui/scrolling-number";

export default function Demo() {
  return (
    <ScrollingNumber
      number={48}
      fromNumber={0}
      itemsSize={34}
      className="w-40 text-2xl"
    />
  );
}
import { ScrollingNumber } from "@/components/prequelui/scrolling-number";

export function Variant() {
  return (
    <ScrollingNumber tempo={1.2}>
      …
    </ScrollingNumber>
  );
}
03

Animation

The number is a mechanical band. On first view the band leaves its resting index and settles under a fixed marker with a damped spring; changing the value retargets the same motion instead of restarting it.

  • Band spring: stiffness 90, damping 30, restDelta 0.001.
  • Two neighbours above and below stay visible, faded by the mask.
  • The marker and the edge mask are decorative and hidden from assistive technology.
  • Reduced motion places the band at its final index with no travel.
band 90 / 30restDelta 0.0012 side itemsmasked edges
04

API Reference

Each part accepts the usual HTML props in addition to the motion props below. No accessibility prop is hidden behind the animation layer.

ScrollingNumber

PropTypeDefault
numbernumber0
fromNumbernumber0
stepnumber1
itemsSizenumber30
sideItemsCountnumber2
inViewbooleanfalse
inViewOncebooleantrue
delaynumber0
onCompleted() => void—
transitionTransitioncomponent spring
classNamestring—

Next component

Sliding Number

An odometer where every digit rolls independently.