Join our Discord Community
Text

Counting Number

Animated counting number with spring transitions and in-view detection. Perfect for React applications requiring smooth number animations with Next.js integration and TypeScript support.

Powered by

Loading component...

Installation

npx shadcn@latest add https://www.shadcn.io/registry/counting-number.json
npx shadcn@latest add https://www.shadcn.io/registry/counting-number.json
pnpm dlx shadcn@latest add https://www.shadcn.io/registry/counting-number.json
bunx shadcn@latest add https://www.shadcn.io/registry/counting-number.json

Features

  • Spring animations with customizable stiffness and damping using Motion's useSpring hook
  • In-view detection triggers animations when component enters viewport with configurable margins
  • Decimal support with customizable separators and precision control for international formatting
  • Padding options for consistent width displays with leading zeros and number alignment
  • TypeScript support with complete interface definitions for all animation and formatting props
  • Performance optimized using Motion values for smooth 60fps animations without re-renders

Examples

Decimal Numbers

Loading component...

Numbers with decimal places and custom separators for international formatting.

From Number Animation

Loading component...

Count down from a starting number to demonstrate reverse animations.

Use Cases

This free open source React component works well for:

  • Statistics dashboards - Animated counters for metrics and KPIs in Next.js applications
  • Landing pages - Eye-catching number reveals for achievements using TypeScript and Tailwind CSS
  • Progress indicators - Dynamic counting for completion percentages and user milestones
  • Financial displays - Currency amounts with proper decimal formatting and animations

API Reference

CountingNumber

PropTypeDefaultDescription
numbernumberrequiredTarget number to count towards
fromNumbernumber0Starting number for the animation
decimalPlacesnumber0Number of decimal places to display
decimalSeparatorstring"."Character used for decimal separation
padStartbooleanfalsePad with leading zeros to maintain consistent width
inViewbooleanfalseOnly animate when component enters viewport
inViewMarginstring"0px"Margin for in-view detection trigger
inViewOncebooleantrueOnly trigger in-view animation once
transitionSpringOptions{ stiffness: 90, damping: 50 }Motion spring configuration for animation timing
classNamestring-CSS classes for styling the number display

Animation Configuration

  • stiffness - Controls animation speed (higher = faster)
  • damping - Controls bounce/oscillation (higher = less bounce)
  • mass - Controls animation weight (higher = slower start/stop)

Implementation Notes

  • Uses Motion's useMotionValue for performance optimization
  • In-view detection uses Intersection Observer API
  • Number formatting handles negative values and edge cases
  • Supports all standard span HTML attributes and events
  • Animation automatically cleans up on component unmount
  • Decimal separator replacement works with any Unicode character