Settle counter
A number where each changed digit arrives big and faint, then settles in as the old one fades. Use it large, on a live count in a hero or dashboard.
npx shadcn@latest add https://impeccable-ui.com/r/settle-counter.jsonRun it in a project set up with shadcn. No other packages needed. Or open and copy the file into components/ui/settle-counter.tsx.
Types
Two types, playing the same numbers. Commas is the default: a comma sits between thousands and settles in like a digit when the number grows past 999. No commas shows the digits alone.
<SettleCounter value={n} />separator=""<SettleCounter value={83295} /> // 83,295
<SettleCounter value={83295} separator="" /> // 83295Prompts
Paste one into Claude Code, Cursor or any AI coding tool. Install adds this exact counter and asks only where it goes. Blend asks four short questions (where, commas or not, the type and the color), then fits it to your product without changing how it settles.
# Settle counter
A 1-file React component from Impeccable. Add it to this project so it works and looks exactly like the source below, in the one place I choose, and change nothing else.
A number where every digit that changes counts to its new number and settles into place: the old digit shrinks and fades away, the place counts through every number in between (1, 2, 3, 4, 5, 6), and the last one arrives bigger and faint (1.6 times the size, at 30%) and settles down to the size of the digits around it. Digits that stay the same don't move, and commas between thousands come and go the same way. When the number gets longer, its frame first widens to make room, then the new digit settles into the gap; when it gets shorter, the digit leaves first, then the frame closes.
## Before you build: one question
Look through this project first: its hero, stats or numbers sections, dashboard cards, pricing, and any place that already shows a number that changes (a live count, a total, a price, a score). Then ask me this in one message and wait for my answer:
- **Where should it go?** Suggest the 1–3 numbers in my code it fits best, what makes each one change, and the size it would take there. I can pick one or name another.
*Why: the settle only shows when the number changes, and shows best large, so it belongs on a number my visitors watch.*
Ask nothing else. If I say *skip*, use the best suggestion.
## Keep it as it is
The swap (the old digit shrinking and fading, the count through every number in between, and the last one arriving 1.6 times bigger at 30% and settling), the frame widening before a new digit lands and closing after one leaves, and their timing and easing, are the design. Keep them exactly as in the source. If something doesn't fit my project, tell me instead of changing it.
- Add only the component file and the one place I picked. If it replaces an existing number there, pass that same value to `value` and remove only the old display. Don't add packages, change other files, or restyle anything.
- Don't add the demo parts from the Impeccable website: the "Humans on Impeccable UI right now" label, the made-up numbers it plays on its own, the Change number button, the dotted card and the home page's TV.
## Fastest path
If this project has a `components.json` (shadcn), run `npx shadcn@latest add https://impeccable-ui.com/r/settle-counter.json`.
If the command succeeds, only fix import paths to match this project and skip ahead. If it fails or there is no `components.json`, build it by hand as below.
## Build it
- Stack: React 18 or 19 with TypeScript. No other packages: every move is a short Web Animations API call (`element.animate`) that ends on its own, and the counting steps are short timers that stop when the count lands, and its styles sit in a `<style>` tag inside the file.
- JavaScript project? Name the file `settle-counter.jsx` and remove the type annotations; nothing else changes.
- Create this file, in this project's usual place for components:
- `components/ui/settle-counter.tsx`
- Keep these exports and their names: `SettleCounter` (also the default export) and `SettleCounterProps`.
- Keep `"use client"` at the top in Next.js App Router projects. In other setups it is harmless.
- Keep the tuning values at the top exactly as written: `IN_MS`, `IN_EASE`, `GROW`, `FAINT`, `OUT_MS`, `OUT_EASE`, `SHRINK`, `WIDEN_MS`, `WIDEN_EASE`, `LAND_AT`, `CLOSE_AT`, `STAGGER_MS`, `FADE_MS`, `STEP_GAP`, `RUN_MAX`, `RUN_CURVE`, `STEP_IN_MS`, `STEP_GROW`, `STEP_OUT_MS` and the `CSS` block. They are the design and its timing.
- Keep the fallbacks: the first number is drawn as it is, with no motion, so the server and the browser draw the same thing. With `prefers-reduced-motion: reduce` nothing grows, shrinks or widens: the new digit simply fades in where it stands. Screen readers get the whole number as hidden text, so they never read half-changed digits.
## Use it
```tsx
"use client";
import { SettleCounter } from "@/components/ui/settle-counter";
export function LiveCount({ count }: { count: number }) {
return <SettleCounter value={count} aria-label="People online:" className="text-6xl font-medium tracking-tight" />;
}
```
- `value` is the number to show; give it a new value and the changed digits settle. A string is shown as written, so `"$1.2k"` works too.
- `separator` is the mark between thousands. It is a comma by default (83,295); `separator=""` shows the digits alone.
- Size, weight, font and color come from the text around it, so set them with `className` or `style`.
- A new digit starts 1.6 times bigger, so leave about a third of its height free above and below it.
## How the counter works
Read this before you touch anything, so you know what the code does and why it must stay as it is.
1. **The places.** Each character of the number has its own place, counted from the left. Numbers use even-width digits (tabular numbers), so the number never jiggles sideways. It takes its font, size, weight and color from the text around it.
2. **The swap.** When the digit in a place changes, the old digit shrinks to half its size and fades out in 0.38 seconds (it is gone early, with no tail). The place then counts to the new digit, up or down, through every number in between (1 to 6 shows 2, 3, 4 and 5): each in-between number arrives 1.3 times bigger and leaves in 0.18 seconds, the gaps growing so the count slows into the last number, and the whole count takes at most 0.56 seconds. The last number appears 1.6 times bigger at 30% and settles to full size and full color in 0.62 seconds, quick at first with a long, soft landing. Places whose digit stays the same don't move.
3. **A longer number.** The frame widens first: the new place opens from nothing to one digit wide in 0.42 seconds, starting and ending gently. 0.3 seconds in, when it is nearly open, the new digit (and any other digit that changed) settles in the same way as a swap, so it all lands together.
4. **A shorter number.** The leaving digit shrinks and fades first, and 0.16 seconds later the frame starts closing behind it in 0.42 seconds.
5. **Several at once.** Digits that change together start 45ms apart, left to right, like a small wave.
6. **Fast changes.** If a new number comes while digits are still settling, each one leaves from wherever it is, so nothing jumps. Nothing runs between changes.
## Check
- It type-checks and the page renders with no console errors.
- When the number changes, only the changed digits move: each counts through the numbers in between (1 to 6 shows 2, 3, 4, 5), then the last one arrives big and faint and settles in about 0.6 seconds. When a digit is added, the number first widens, then the digit settles into the gap; when one is removed, it fades first, then the number closes up.
- It looks right in light and dark mode (check both): it takes the text color around it.
- It fits on a phone without scrolling sideways, at the size I chose, and the motion stays smooth.
- With `prefers-reduced-motion: reduce`, each new digit only fades in where it stands, with no growing or widening.
- Nothing else on the site looks or behaves differently.
- Finish with a short report: the files you added or changed, where it's placed, and every place where you had to do something differently from the source, and why.
## Source
The reference implementation. Copy it as-is, then apply only the changes listed above.
### `components/ui/settle-counter.tsx`
```tsx
"use client";
/**
* Settle counter, from Impeccable.
*
* A number where every digit that changes settles into place. The old digit
* shrinks and fades away while the new one arrives bigger and faint (1.6x,
* 30% see-through) and settles down to the size of the digits around it.
* A digit that changes counts there: from 1 to 6 it shows 2, 3, 4 and 5 on the
* way, quick at first and slowing into the last one, which settles as above.
* Digits that stay the same don't move. Commas between thousands come and go
* the same way.
*
* When the number gets longer, its frame first widens to make room, then the
* new digit settles into the gap. When it gets shorter, the digit leaves first,
* then the frame closes.
*
* No packages. It takes its font, size and color from the text around it.
*/
import { useCallback, useLayoutEffect, useEffect, useRef, useState, type CSSProperties } from "react";
export type SettleCounterProps = {
/** The number to show. A string is shown as written, so "$1.2k" or "08:30" work too. */
value: number | string;
/** Put between thousands: "," gives 8,329. "" for none. Only for number values. Default: ",". */
separator?: string;
/** Name for screen readers, read before the number. */
"aria-label"?: string;
className?: string;
style?: CSSProperties;
};
/* ---------- the design: keep as written ---------- */
const IN_MS = 620; // a new digit, from big and faint to settled
const IN_EASE = "cubic-bezier(.22,1,.36,1)"; // leaves quickly, then a long soft landing
const GROW = 1.6; // how big a new digit starts (1 = the size of the others)
const FAINT = 0.3; // how visible a new digit starts (0.3 = 30%)
const OUT_MS = 380; // the old digit shrinking and fading away
const OUT_EASE = "cubic-bezier(.33,1,.68,1)"; // gone early, no tail
const SHRINK = 0.5; // the old digit's size by the time it is gone
const WIDEN_MS = 420; // the frame opening or closing by one digit
const WIDEN_EASE = "cubic-bezier(.65,0,.35,1)"; // starts and ends gently, so it never jolts
const LAND_AT = 300; // when the digits start settling while the frame widens (ms)
const CLOSE_AT = 160; // when the frame starts closing after a digit starts leaving (ms)
const STAGGER_MS = 45; // between digits that change together, left to right
const FADE_MS = 180; // reduced motion: a plain crossfade
// Counting: a digit that changes steps through every number in between (1, 2, 3, 4, 5, 6), up or down.
const STEP_GAP = 70; // time per in-between number, before the cap
const RUN_MAX = 560; // the longest the in-between numbers may take, so 0 to 9 never drags
const RUN_CURVE = 1.35; // above 1: quick at first, then slowing into the last number
const STEP_IN_MS = 240; // an in-between number arriving
const STEP_GROW = 1.3; // how big an in-between number starts (the last one starts at GROW)
const STEP_OUT_MS = 180; // an in-between number leaving
const CSS = `
.stlc{display:inline-flex;align-items:center;line-height:1;font-variant-numeric:tabular-nums;white-space:nowrap;vertical-align:middle}
.stlc-slot{position:relative;display:inline-block;height:1em}
.stlc-size{display:inline-block;visibility:hidden}
.stlc-glyph{position:absolute;inset:0;display:flex;align-items:center;justify-content:center;white-space:pre}
.stlc-sr{position:absolute;width:1px;height:1px;padding:0;margin:-1px;overflow:hidden;clip:rect(0,0,0,0);white-space:nowrap;border:0}
`;
/* ---------- text ---------- */
function show(value: number | string, separator: string) {
if (typeof value !== "number") return String(value);
if (!Number.isFinite(value)) return String(value);
const [int, dec] = Math.abs(value).toString().split(".");
const grouped = separator ? int.replace(/\B(?=(\d{3})+(?!\d))/g, separator) : int;
return (value < 0 ? "-" : "") + grouped + (dec ? "." + dec : "");
}
const px = (el: Element) => parseFloat(getComputedStyle(el).width) || 0;
/**
* The places of a number, from the left. Digits are counted from the left, so a digit
* added at the end is the only one that moves (8329 to 83295). A comma or any other mark
* is a place of its own, named by how many digits come before it, so when the number grows
* from 8,329 to 83,295 the digits stay put and only the comma moves to its new spot.
*/
function places(text: string) {
let digits = 0;
let marks = 0;
return [...text].map((char) => {
if (char >= "0" && char <= "9") {
marks = 0;
return { key: `d${digits}`, rank: digits++ * 100 + 99, char };
}
return { key: `s${digits}.${marks}`, rank: digits * 100 + marks++, char };
});
}
/** The digits between two digits, in counting order: "1" to "6" gives 2, 3, 4, 5; "6" to "1" gives 5, 4, 3, 2. */
function between(from: string, to: string) {
const a = Number(from);
const b = Number(to);
if (!/^[0-9]$/.test(from) || !/^[0-9]$/.test(to)) return [];
const dir = b > a ? 1 : -1;
const out: string[] = [];
for (let d = a + dir; d !== b; d += dir) out.push(String(d));
return out;
}
/* ---------- one digit on screen ---------- */
type GlyphData = {
id: number;
char: string;
enter: boolean;
out: boolean;
delay: number;
/** An in-between number while counting: arrives smaller and leaves faster. */
quick?: boolean;
};
function Glyph({ g, reduced, onGone }: { g: GlyphData; reduced: boolean; onGone: (id: number) => void }) {
const ref = useRef<HTMLSpanElement>(null);
const anim = useRef<Animation | null>(null);
// Arrive: big and faint, then settle to the size and color of the others.
useLayoutEffect(() => {
const el = ref.current;
if (!el || !g.enter) return;
if (typeof el.animate !== "function") {
el.style.opacity = "1";
return;
}
anim.current = el.animate(
reduced
? [{ opacity: 0 }, { opacity: 1 }]
: [
{ opacity: FAINT, transform: `scale(${g.quick ? STEP_GROW : GROW})` },
{ opacity: 1, transform: "scale(1)" },
],
{ duration: reduced ? FADE_MS : g.quick ? STEP_IN_MS : IN_MS, easing: reduced ? "linear" : IN_EASE, delay: g.delay, fill: "forwards" },
);
// Settled: keep it visible on its own and let the animation go.
const a = anim.current;
a.onfinish = () => {
el.style.opacity = "1";
a.cancel();
};
// eslint-disable-next-line react-hooks/exhaustive-deps
}, []);
// Leave: shrink and fade from wherever it is now (even halfway through arriving).
useLayoutEffect(() => {
const el = ref.current;
if (!el || !g.out) return;
if (typeof el.animate !== "function") return onGone(g.id);
const now = getComputedStyle(el);
const from = { opacity: now.opacity, transform: now.transform === "none" ? "scale(1)" : now.transform };
anim.current?.cancel();
const a = el.animate(
reduced ? [{ opacity: from.opacity }, { opacity: 0 }] : [from, { opacity: 0, transform: `scale(${SHRINK})` }],
{ duration: reduced ? FADE_MS : g.quick ? STEP_OUT_MS : OUT_MS, easing: reduced ? "linear" : OUT_EASE, delay: g.delay, fill: "both" },
);
anim.current = a;
a.onfinish = () => onGone(g.id);
// eslint-disable-next-line react-hooks/exhaustive-deps
}, [g.out]);
useEffect(() => () => anim.current?.cancel(), []);
return (
// A new digit stays hidden while it waits for its turn (the frame opening); its animation then holds it in place.
<span ref={ref} className="stlc-glyph" style={g.enter ? { opacity: 0 } : undefined}>
{g.char}
</span>
);
}
/* ---------- one place in the number ---------- */
type SlotData = {
/** Which place it is: "d3" = the 4th digit from the left, "s1.0" = the first mark (like a comma) after the 1st digit. */
key: string;
/** Its spot in the line, so places on their way out stay where they were. */
rank: number;
char: string;
/** The numbers to count through on the way to `char`, like ["2", "3", "4", "5"] for 1 to 6. */
steps: string[];
/** On its way out: the digit leaves, then the frame closes. */
leaving: boolean;
/** New place: the frame opens first. */
fresh: boolean;
delay: number;
/** Goes up by one for every change, so the slot knows when to move. 0 = drawn as it is, no motion. */
gen: number;
};
function Slot({ s, reduced, onGone }: { s: SlotData; reduced: boolean; onGone: (key: string, gen: number) => void }) {
const box = useRef<HTMLSpanElement>(null);
const size = useRef<HTMLSpanElement>(null);
const width = useRef<Animation | null>(null);
const ids = useRef(1);
const [glyphs, setGlyphs] = useState<GlyphData[]>(() => [
{ id: 0, char: s.char, enter: s.gen > 0, out: false, delay: s.delay },
]);
const handled = useRef(-1); // the last change this place has acted on (so a second run in React's strict mode does nothing)
const was = useRef(0); // the frame's width after the last change
const timers = useRef<number[]>([]); // the counting steps still to come
const stop = () => {
timers.current.forEach(clearTimeout);
timers.current = [];
};
// Show the next number in this place: the ones on screen leave as it arrives.
const show = (char: string, delay: number, quick: boolean) =>
setGlyphs((gs) => {
const kept = gs.map((g) => (g.out ? g : { ...g, out: true, delay }));
// Never more than three leaving at once: drop the oldest if numbers change faster than they settle.
const leaving = kept.filter((g) => g.out);
const drop = new Set(leaving.slice(0, Math.max(0, leaving.length - 3)).map((g) => g.id));
return [...kept.filter((g) => !drop.has(g.id)), { id: ids.current++, char, enter: true, out: false, delay, quick }];
});
// The frame: open from `from` to the digit's width, or close to 0 and then tell the number it is gone.
const frame = (from: number, to: number, delay: number, closing: boolean) => {
const b = box.current;
width.current?.cancel();
width.current = null;
if (!b || typeof b.animate !== "function" || Math.abs(from - to) < 0.5) {
if (closing) onGone(s.key, s.gen);
return;
}
const a = b.animate([{ width: `${from}px` }, { width: `${to}px` }], {
duration: reduced ? 0 : WIDEN_MS,
easing: WIDEN_EASE,
delay: reduced ? 0 : delay,
fill: closing ? "both" : "backwards",
});
width.current = a;
a.onfinish = () => {
if (closing) onGone(s.key, s.gen);
else if (width.current === a) width.current = null;
};
};
useLayoutEffect(() => {
const b = box.current;
const sz = size.current;
if (!b || !sz) return;
if (handled.current === s.gen) return;
const firstRun = handled.current === -1;
handled.current = s.gen;
const to = px(sz);
if (firstRun) {
was.current = to;
if (s.gen > 0 && s.fresh) frame(0, to, 0, false);
return;
}
stop();
const now = width.current ? px(b) : null;
if (s.leaving) {
// The digit leaves first, then the frame closes behind it.
setGlyphs((gs) => gs.map((g) => (g.out ? g : { ...g, out: true, delay: s.delay })));
frame(now ?? was.current, 0, s.delay + (reduced ? 0 : CLOSE_AT), true);
was.current = 0;
return;
}
// A new digit (or the same place coming back): open or resize the frame, then the new digit settles in.
frame(now ?? (s.fresh ? 0 : was.current), to, 0, false);
was.current = to;
const run = reduced || s.fresh ? [] : s.steps;
if (!run.length) {
show(s.char, s.delay, false);
return;
}
// Count: every number in between gets its turn, the gaps growing so it slows into the last one.
const m = run.length;
const span = Math.min(RUN_MAX, m * STEP_GAP);
[...run, s.char].forEach((char, k) => {
const at = s.delay + span * (k / m) ** RUN_CURVE;
const go = () => show(char, 0, k < m);
if (at < 1) go();
else timers.current.push(window.setTimeout(go, at));
});
// eslint-disable-next-line react-hooks/exhaustive-deps
}, [s.gen]);
useEffect(() => stop, []);
const gone = useCallback((id: number) => setGlyphs((gs) => gs.filter((g) => g.id !== id)), []);
return (
<span ref={box} className="stlc-slot">
<span ref={size} className="stlc-size">
{s.char}
</span>
{glyphs.map((g) => (
<Glyph key={g.id} g={g} reduced={reduced} onGone={gone} />
))}
</span>
);
}
/* ---------- the number ---------- */
export function SettleCounter({ value, separator = ",", "aria-label": ariaLabel, className, style }: SettleCounterProps) {
const text = show(value, separator);
const [slots, setSlots] = useState<SlotData[]>(() =>
places(text).map((p) => ({ ...p, steps: [], leaving: false, fresh: false, delay: 0, gen: 0 })),
);
const [reduced, setReduced] = useState(false);
const last = useRef(text);
const gen = useRef(0);
useEffect(() => {
const q = window.matchMedia("(prefers-reduced-motion: reduce)");
const on = () => setReduced(q.matches);
on();
q.addEventListener("change", on);
return () => q.removeEventListener("change", on);
}, []);
// A new number: compare it with what is on screen, place by place.
useLayoutEffect(() => {
if (text === last.current) return;
last.current = text;
const next = places(text);
setSlots((prev) => {
const was = new Map(prev.map((p) => [p.key, p]));
const now = new Set(next.map((n) => n.key));
// When a place is added, every change waits for the frame to open, so they all land together.
const grows = next.some((n) => !was.get(n.key) || was.get(n.key)!.leaving);
const base = !reduced && grows ? LAND_AT : 0;
const step = reduced ? 0 : STAGGER_MS;
// The new places plus the ones on their way out, in line order.
const all = [
...next.map((n) => ({ n, p: was.get(n.key), rank: n.rank })),
...prev.filter((p) => !now.has(p.key)).map((p) => ({ n: null, p, rank: p.rank })),
].sort((x, y) => x.rank - y.rank);
let order = 0;
const out: SlotData[] = [];
for (const { n, p } of all) {
if (n && (!p || p.leaving)) out.push({ ...n, steps: [], leaving: false, fresh: true, delay: base + order++ * step, gen: ++gen.current });
else if (n && p && p.char !== n.char)
out.push({ ...p, char: n.char, steps: between(p.char, n.char), fresh: false, delay: base + order++ * step, gen: ++gen.current });
else if (n && p) out.push(p);
else if (p) out.push(p.leaving ? p : { ...p, leaving: true, fresh: false, delay: order++ * step, gen: ++gen.current });
}
return out;
});
}, [text, reduced]);
// A place that has finished leaving is taken away.
const gone = useCallback(
(key: string, g: number) => setSlots((ss) => ss.filter((x) => !(x.key === key && x.leaving && x.gen === g))),
[],
);
return (
<span className={["stlc", className].filter(Boolean).join(" ")} style={style}>
<style>{CSS}</style>
<span className="stlc-sr">{ariaLabel ? `${ariaLabel} ${text}` : text}</span>
<span aria-hidden="true" style={{ display: "contents" }}>
{slots.map((s) => (
<Slot key={s.key} s={s} reduced={reduced} onGone={gone} />
))}
</span>
</span>
);
}
export default SettleCounter;
```
Usage
Pass the number to value and size it with className. Leave a little room above and below it, where a new digit lands bigger before it settles.
"use client";
import { SettleCounter } from "@/components/ui/settle-counter";
// Give it a new value and only the digits that changed settle into place.
// Size, weight and color come from the text around it.
export function LiveCount({ count }: { count: number }) {
return <SettleCounter value={count} aria-label="People online:" className="text-6xl font-medium tracking-tight" />;
}How it moves
Only the digits that change move. The rest stay perfectly still.
A digit that changes counts to its new number, up or down, showing every number in between: from 1 to 6 you see 2, 3, 4 and 5 on the way. Each one arrives a little bigger (1.3 times) and leaves in 0.18 seconds. The count is quick at first and slows into the last number, and never takes more than 0.56 seconds, so 0 to 9 doesn't drag. The last number arrives 1.6 times bigger at 30% and settles to full size and full color in 0.62 seconds: quick at first, then a long, soft landing. The old digit shrinks to half its size and fades out in 0.38 seconds, gone early with no tail. When the number gets longer, the frame opens first, one digit wide in 0.42 seconds, easing in and out so it never jolts, and the new digit starts settling 0.3 seconds in, when there is almost room for it. When the number gets shorter, the digit leaves first and the frame closes behind it. Digits that change together start 45ms apart, left to right. If a new number comes while digits are still settling, each one leaves from wherever it is, so nothing jumps. With reduced motion nothing grows or widens: each new digit simply fades in where it stands.
Props
| Prop | Default | What it does |
|---|---|---|
value | — | The number to show. Give it a new one and the changed digits settle. A string is shown as written, like "$1.2k". |
separator | "," | The mark between thousands: "," gives 83,295. Use "" for none, or another mark like ".". Only for number values. |
aria-label | — | Read by screen readers before the number, like "People online:". The number itself is read from hidden text. |
className / style | — | On the number. It takes its font, size, weight and color from here or from the text around it. |