Overview
TheCounter component displays an animated flip-clock style counter that animates from zero (or starting value) to the target amount. Each digit flips individually for a mechanical counter effect.
Import
Usage
Basic Counter
Custom Colors
Large Display Counter
Small Counter
Dynamic Counter
Props
Target number to count up to.The component automatically:
- Starts from
amount - 10(or 0 if amount < 10) - Counts up by 1 every 400ms
- Stops when reaching the target amount
- Restarts animation when amount changes
Height in pixels for each digit block.
Width in pixels for each digit block.
Font size in pixels for the numbers.Typically set to ~80% of height for proper visual balance.
Text color for the digits.Default: Inherits from CSS variables
Background color for each digit block.Default: Inherits from CSS variables
Border/divider color between digit segments.Used for the horizontal line separating top and bottom halves of each digit.Default: Inherits from CSS variables
Features
- Flip animation: Each digit flips individually like a mechanical counter
- Auto-start counting: Begins from
amount - 10and counts to target - Dynamic updates: Re-animates when amount prop changes
- Customizable styling: Full control over colors, sizes, and typography
- Multi-digit support: Automatically handles any number of digits
- Smooth transitions: 400ms intervals for natural counting effect
- CSS-based animations: Uses CSS modules for performant animations
Animation Behavior
- Initial render: Sets counter to
amount - 10(or 0 if amount < 10) - Animation starts: After mount, increments by 1 every 400ms
- Completion: Stops when counter reaches target amount
- Re-animation: Resets and re-animates when amount prop changes
Digit Flip Mechanism
Each digit consists of two halves:- Top half: Shows current digit
- Bottom half: Shows next digit
- Animation: Rotates 180° when value changes
- Result: Smooth flip transition between digits
Size Guidelines
Recommended proportions for balanced appearance:| Height | Width | Font Size | Use Case |
|---|---|---|---|
| 40px | 28px | 24px | Small counters, mobile |
| 60px | 40px | 32px | Standard desktop |
| 80px | 55px | 44px | Large displays |
| 100px | 70px | 56px | Hero sections |
width ≈ height × 0.7, fontSize ≈ height × 0.8
CSS Variables
The component uses CSS custom properties for theming:Performance Considerations
- Uses
window.setIntervalfor counting animation - Automatically clears interval on unmount
- Re-creates interval when amount changes
- CSS animations handled by GPU for smooth performance
- Recommended for amounts < 1,000,000 (digit count affects rendering)
Best Practices
- Match
fontSizeto height for visual balance (typically 80% of height) - Use contrasting colors for readability
- Keep digit blocks consistent size across your app
- Consider loading state while calculating amounts
- Use for impressive number reveals (stats, metrics, achievements)
- Avoid rapid amount changes (animation needs time to complete)
- Test with maximum expected digit count for layout stability
Use Cases
- Statistics dashboards: User counts, revenue, metrics
- Achievement screens: Points, scores, milestones
- Landing pages: Impressive numbers (customers, downloads)
- Gamification: Score counters, level progression
- Analytics: Real-time visitor counts
- Countdowns: Days until event (when counting up from 0)
Accessibility
- Uses
data-testid="fcc-container"for testing - Semantic HTML structure
- Consider adding
aria-labelwith final count:
Browser Support
- Modern browsers (Chrome, Firefox, Safari, Edge)
- Requires CSS animations support
- Uses
window.setInterval(widely supported)
Troubleshooting
Counter doesn’t animate:- Check that
amountprop is changing - Ensure component is mounted when amount updates
- Increase
widthprop - Adjust parent container’s
overflowproperty
- Currently fixed at 400ms intervals
- Modify source code if custom timing is needed
- Increase
fontSizeor decreaseheight/width - Check font-family renders at expected size
Related Components
- ProgressBar - Alternative progress indicator
- Text - For static number display
- Label - For badge-style counters