An animated number component. Dependency-free. Accessible. Customizable.
NumberFlow is an animated number component for React designed to provide smooth, accessible, and highly customizable numerical transitions. It is a dependency-free tool that automatically handles the complexity of animating digits when their value changes.
The main features of this tool include:
Automatic Animated Transitions: The component detects when its value prop changes and automatically triggers a smooth transition between the old and new numbers.
Built-in Formatting and Localization: It leverages the standard Intl.NumberFormat API, allowing you to easily apply formatting options (like currency or compact notation) and specific locales. You can also add custom prefixes and suffixes.
Fine-Grained Animation Control:
Timings: You can customize the duration and easing for layout transforms, digit spin animations, and opacity fades independently.
Trends: You can control the direction of the digits—forcing them to always go up, always go down, or follow the natural direction of the value change.
Continuous Transitions: A dedicated plugin allows numbers to appear to pass through all in-between values during a transition.
Layout Synchronization:
Grouping: The <NumberFlowGroup> component allows you to sync transitions between multiple related number components so they move together harmoniously.
Isolation: The isolate prop can be used to prevent a number's transition from affecting other layout changes on the page.
Advanced Styling Options: NumberFlow uses a custom element under the hood, exposing specific CSS "parts" (like ::part(suffix)) for detailed styling. It also provides custom CSS properties to adjust masking gradients and character heights.
Accessibility and Performance: By default, the tool respects user motion preferences. It also supports the will-change property to optimize performance for numbers that update frequently.
Developer Hooks: It includes the useCanAnimate hook, which allows developers to check if the user's browser supports the necessary animation features and if they have enabled motion preferences.