Skip to content
ProLifetime access for $199, paid once, every future release included
Truffle UI

Stats Counter

FreeNew

Counters with an icon, prefix, suffix and caption that count up as they scroll into view, as a grid, a divided row or a stack, plain or in cards.

Installation

pnpm dlx shadcn@latest add @viewport/stats-counter

First time? Add the @viewport registry to components.json. Setup takes one minute.

Usage

The code behind the preview above.

stats-counter-demo.tsx
"use client";

import { useState } from "react";
import { Coffee, Globe, Package, Smile, Star, Store, TrendingUp, Users } from "lucide-react";
import { StatsCounter, type StatCounter } from "@/components/viewport/stats-counter";

const company: StatCounter[] = [
  { value: 12480, suffix: "+", caption: "Happy customers", icon: <Smile strokeWidth={1.75} /> },
  { value: 48, caption: "Countries served", icon: <Globe strokeWidth={1.75} /> },
  { value: 99.9, suffix: "%", decimals: 1, caption: "Uptime last year", icon: <TrendingUp strokeWidth={1.75} /> },
  { value: 4.9, decimals: 1, caption: "Average rating", icon: <Star strokeWidth={1.75} /> },
];

const store: StatCounter[] = [
  { value: 250000, suffix: "+", caption: "Orders shipped", description: "Since we opened in 2019.", icon: <Package strokeWidth={1.75} />, color: "#f97316" },
  { value: 36, caption: "Stores worldwide", description: "From Lisbon to Seoul.", icon: <Store strokeWidth={1.75} />, color: "#0ea5e9" },
  { value: 1200, caption: "Team members", description: "Half of them work remotely.", icon: <Users strokeWidth={1.75} />, color: "#10b981" },
  { value: 18, prefix: "$", suffix: "M", caption: "Paid to makers", description: "Directly, every month.", icon: <Coffee strokeWidth={1.75} />, color: "#8b5cf6" },
];

const growth: StatCounter[] = [
  { value: 3.2, prefix: "$", suffix: "B", decimals: 1, caption: "Processed in 2025" },
  { value: 148, suffix: "%", caption: "Revenue growth" },
  { value: 24, suffix: "/7", caption: "Human support" },
];

const views = [
  { id: "plain", label: "Plain" },
  { id: "cards", label: "Cards" },
  { id: "dark", label: "Dark row" },
  { id: "color", label: "Coloured" },
  { id: "single", label: "Single" },
] as const;

export default function StatsCounterDemo() {
  const [view, setView] = useState<(typeof views)[number]["id"]>("plain");

  return (
    <div className="w-full max-w-5xl min-w-0">
      <div className="mb-5 flex flex-wrap justify-center gap-1" role="group" aria-label="Style">
        {views.map((v) => (
          <button
            key={v.id}
            type="button"
            aria-pressed={v.id === view}
            onClick={() => setView(v.id)}
            className="rounded-md px-3 py-1 text-xs font-medium text-muted-foreground outline-none transition-colors hover:text-foreground focus-visible:ring-2 focus-visible:ring-ring aria-pressed:bg-foreground aria-pressed:text-background"
          >
            {v.label}
          </button>
        ))}
      </div>
      {view === "plain" && <StatsCounter counters={company} surface="card" title="Our numbers speak for themselves" />}
      {view === "cards" && <StatsCounter counters={company} card="card" align="left" iconStyle="badge" />}
      {view === "dark" && <StatsCounter counters={growth} layout="row" surface="dark" size="lg" title="Company growth" text="Three years in, and still doubling." />}
      {view === "color" && <StatsCounter counters={store} card="filled" columns={2} align="left" iconPosition="left" iconStyle="badge" size="sm" />}
      {view === "single" && (
        <StatsCounter
          counters={[{ value: 1284903, caption: "Cups of coffee served", description: "And counting, one flat white at a time.", icon: <Coffee strokeWidth={1.5} /> }]}
          layout="stacked"
          size="lg"
          background="linear-gradient(135deg, #7c2d12, #c2410c 55%, #f59e0b)"
          duration={3}
        />
      )}
    </div>
  );
}

Props

PropTypeDefault
counters*StatCounter[]—
layout"grid" | "row" | "stacked"

`grid` wraps into columns, `row` is one line split by dividers, `stacked` is a single column.

"grid"
card"none" | "card" | "filled" | "outline"

How each counter is boxed.

"none"
surface"none" | "card" | "dark"

The panel behind all counters. `dark` is always near-black with white text.

"none"
backgroundstring

Any CSS background for the panel; text turns white.

—
columns2 | 3 | 4

Most columns the grid may use; it drops columns as the container narrows.

4
align"center" | "left""center"
iconPosition"top" | "left"

Where the icon sits relative to the number.

"top"
iconStyle"plain" | "badge"

`badge` sets the icon on a tinted circle.

"plain"
size"sm" | "md" | "lg"

Size of the numbers.

"md"
accent"number" | "icon" | "both"

Which part takes the accent colour.

"both"
titlestring—
textstring—
animation"count" | "fade" | "none"

`count` runs the digits up, `fade` lifts the final number in, `none` shows it at once.

"count"
durationnumber

Seconds the count takes.

2
staggernumber

Seconds between one counter starting and the next.

0.12
separatorboolean

Group digits with the locale's thousands separator.

true
localestring

BCP 47 locale used to format numbers.

"en-US"
classNamestring—

Accessibility

  • A description list: each caption is the term for its number.
  • Screen readers get the final value once; the running digits are hidden from them.
  • The final width is reserved and numerals are tabular, so nothing shifts while counting.
  • Shows the final values straight away under reduced motion.
  • Icons are decorative and hidden from assistive tech.