Animated number display with smooth sliding transitions for each digit. Perfect for counters, stats, prices, and any numeric values that change over time. It is a server component with no JavaScript of its own: every digit is a 0–9 column shifted by a CSS variable, and a CSS transition slides it when the value prop changes.
Browser Support
Feature
Baseline
Your browser
linear() easing
Smooths the digit animation.
Your browser:
Preview
Click the buttons to see the sliding animation.
1337
Installation
Usage
import { SlidingNumber } from "@/components/ui/sliding-number"
export default function Example() {
const [count, setCount] = useState(0)
return (
<div className="text-4xl font-bold">
<SlidingNumber value={count} />
</div>
)
}Examples
Counter with Padding
Use padStart to maintain consistent width with leading zeros.
000
<SlidingNumber value={count} padStart={3} />
// 0 → "000", 5 → "005", 42 → "042", 100 → "100"Timer
Combine multiple SlidingNumber components for MM:SS format.
00:00
const minutes = Math.floor(seconds / 60)
const secs = seconds % 60
<div className="flex items-center font-mono">
<SlidingNumber value={minutes} padStart={2} />
<span>:</span>
<SlidingNumber value={secs} padStart={2} />
</div>Price Display
Wrap with currency symbol and suffix for pricing.
$99/mo
<div className="text-3xl font-bold">
$<SlidingNumber value={price} />
<span className="text-lg text-muted-foreground">/mo</span>
</div>Stats Dashboard
Display multiple animated statistics.
12847
Users
98432
Downloads
4521
Stars
<div className="grid grid-cols-3 gap-8">
<div>
<SlidingNumber value={users} />
<span>Users</span>
</div>
<div>
<SlidingNumber value={downloads} />
<span>Downloads</span>
</div>
</div>Props
| Prop | Type | Default | Description |
|---|---|---|---|
| value | number | - | The number to display |
| padStart | number | 0 | Pad with leading zeros to this length |
| decimalSeparator | string | "." | Character used as decimal separator |
| transition | string | spring linear() | CSS transition for the digit columns, for example "transform 300ms ease-out". The default is a spring-like linear() curve |
| className | string | - | Additional CSS classes |
Features
- Smooth animations — a spring-like CSS transition on a linear() curve, no animation library
- Per-digit animation — each digit animates independently for natural effect
- Leading zeros — padStart for consistent width display
- Separator support — handles decimal points and thousands separators
- Custom transitions — pass any CSS transition string to change the feel
- Tabular nums — uses tabular-nums for aligned digit widths