# Stats row (themes.dev UI block)

A section header and three or four figures in a row, each a large value over its label; a description list with tabular numerals. Black and white, dark mode, shadcn-compatible; React, Astro and plain HTML.

26% of 289 about pages and 20% of 671 home pages we studied have a stats section.

## Install

- React: `npx shadcn@latest add https://www.themes.dev/ui/r/stats-row.json`
- Astro: `npx shadcn@latest add https://www.themes.dev/ui/r/astro/stats-row.json`
- HTML: https://www.themes.dev/ui/r/html/stats-row.html (with https://www.themes.dev/ui/r/html/caseroom.css)

Page: https://www.themes.dev/ui/blocks/stats-row/ · Rules for agents: https://www.themes.dev/ui/AGENT.md

## Code

### stats-row.astro

```astro
---
import SectionHeader from '@/components/ui/section-header.astro';
import { cn } from '@/lib/utils';
import { statsRow as c, type StatsRowContent } from './stats-row.classes';

type Props = StatsRowContent & { class?: string };
const { kicker, title, description, stats, id, class: className } = Astro.props;
---

<section aria-labelledby={`${id}-title`} class={cn(c.root, className)}>
  <div class={c.inner}>
    <SectionHeader id={`${id}-title`} kicker={kicker} title={title} description={description} />
    <dl class={c.list(stats.length)}>
      {
        stats.map((s) => (
          <div class={c.stat}>
            <dt class={c.label}>{s.label}</dt>
            <dd class={c.value}>{s.value}</dd>
          </div>
        ))
      }
    </dl>
  </div>
</section>
```

### stats-row.classes.ts

```tsx
/** Stats row: a section header and three or four figures in one row, each a large value over its label, with a rule
 *  above it (figures are data, and data keeps its lines). A description list: the label is the term and comes first in
 *  the DOM, the value is shown above it with flex-col-reverse. Two across on a phone, the full row from 48rem. Figures
 *  use tabular numerals so a row of them lines up. */
export const statsRow = {
  root: '@container bg-background px-6 py-16 text-foreground @3xl:py-24',
  inner: 'mx-auto flex max-w-6xl flex-col gap-12',
  list: (count: number) => ['m-0 grid grid-cols-2 gap-x-6 gap-y-10', count === 3 ? '@3xl:grid-cols-3' : '@3xl:grid-cols-4', '@3xl:gap-x-10'].join(' '),
  stat: 'flex min-w-0 flex-col-reverse justify-end gap-2 border-t pt-5',
  // 30px on a narrow block so a value like 99.98% fits its half of a phone row; 36px from 24rem, 48px from 48rem.
  value: 'm-0 text-3xl font-semibold tracking-[-0.04em] tabular-nums @sm:text-4xl @3xl:text-5xl',
  label: 'text-base text-pretty text-muted-foreground',
};

export type Stat = { value: string; label: string };
export type StatsRowContent = {
  kicker?: string;
  title: string;
  description?: string;
  stats: Stat[];
  /** Unique on the page; ids the heading. */
  id: string;
};
```

### stats-row.tsx

```tsx
import { SectionHeader } from '@/components/ui/section-header';
import { cn } from '@/lib/utils';
import { statsRow as c, type StatsRowContent } from './stats-row.classes';

export type StatsRowProps = StatsRowContent & { className?: string };

/** A section header and three or four figures in a row, each a large value over its label. */
export function StatsRow({ kicker, title, description, stats, id, className }: StatsRowProps) {
  return (
    <section aria-labelledby={`${id}-title`} className={cn(c.root, className)}>
      <div className={c.inner}>
        <SectionHeader id={`${id}-title`} kicker={kicker} title={title} description={description} />
        <dl className={c.list(stats.length)}>
          {stats.map((s) => (
            <div key={s.label} className={c.stat}>
              <dt className={c.label}>{s.label}</dt>
              <dd className={c.value}>{s.value}</dd>
            </div>
          ))}
        </dl>
      </div>
    </section>
  );
}
```
