A number that counts up to its value, written straight to the DOM.
Installation
Usage
import { CountingNumber } from '@animate-ui/react/primitives/texts/counting-number';
export function Stat() {
return <CountingNumber number={2025} inView />;
}A new number springs on from where the count is instead of restarting it.
Animation
- Counts from
fromNumbertonumberon a spring (stiffness: 90, damping: 50): most of the range goes by in the first second, then the last units tick in slowly (2025 lands after about 4.5s). - The ticking value is written to the DOM directly, without a React render per frame.
transitiontakes other spring options, or any Motion transition with atypeor anease.<AnimateUIProvider tempo>paces the default spring.- Under reduced motion, the number shows its target right away.
- Screen readers read the target value once, never the ticking values.
API Reference
CountingNumber
| Prop | Type | Default |
|---|---|---|
number | number | - |
fromNumber? | number | 0 |
padStart? | boolean | false |
decimalSeparator? | string | '.' |
thousandSeparator? | string | - |
decimalPlaces? | number | 0 |
transition? | SpringOptions | Transition | { stiffness: 90, damping: 50 } |
delay? | number | 0 |
initiallyStable? | boolean | false |
inView? | boolean | false |
inViewMargin? | string | '0px' |
inViewOnce? | boolean | true |
...props? | Omit<React.ComponentProps<'span'>, 'children'> | - |