Stat

Display a key metric with a label, formatted value, trend and countdown

Usage

Stat displays a single metric: a label, a formatted value and an optional trend indicator:

Active users
92,410
+12.4% increase
Size
Diff
import { Stat } from '@mantine/core';

function Demo() {
  return (
    <Stat
      label="Active users"
      value={92410}
      thousandSeparator diff={12.4}
    />
  );
}

Value formatting

Numeric values are formatted with NumberFormatter and support the same formatting props. Numeric strings are formatted the same way, other strings are rendered as is. Use prefix and suffix to add units or currency:

Revenue
$1,340.50
Conversion
4.28%
Storage used
82/ 100 GB
import { Group, Stat } from '@mantine/core';

function Demo() {
  return (
    <Group gap={50}>
      <Stat
        label="Revenue"
        value={1340.5}
        prefix="$"
        decimalScale={2}
        fixedDecimalScale
        thousandSeparator
      />
      <Stat label="Conversion" value={4.28} suffix="%" />
      <Stat label="Storage used" value={82} suffix="/ 100 GB" />
    </Group>
  );
}

To fully control value rendering, pass a formatter function. Formatting props and animate are ignored when formatter is set:

import { Stat } from '@mantine/core';

function Demo() {
  return (
    <Stat
      label="Temperature"
      value={21.5}
      formatter={(value) => `${value} °C`}
    />
  );
}

Trend indicator

Set diff prop to display a trend delta below the value. Positive values are green, negative values are red, zero is dimmed. The delta is formatted as a signed percentage:

Revenue
92,410
+12.4% increase
Churn
1,240
-8.2% decrease
Stable
512
0% no change
import { Group, Stat } from '@mantine/core';

function Demo() {
  return (
    <Group gap={50}>
      <Stat label="Revenue" value={92410} thousandSeparator diff={12.4} />
      <Stat label="Churn" value={1240} thousandSeparator diff={-8.2} />
      <Stat label="Stable" value={512} diff={0} withDiffIcon={false} />
    </Group>
  );
}

Use diffFormatter to change the delta text and withDiffIcon={false} to hide the arrow:

import { Stat } from '@mantine/core';

function Demo() {
  return (
    <Stat
      label="New customers"
      value={482}
      diff={38}
      diffFormatter={(diff) => `${diff > 0 ? '+' : ''}${diff} this week`}
    />
  );
}

Icon

Use icon prop to display an icon next to the value:

Users
92,410
+12.4% increase
Revenue
$1,340.50
+4.1% increase
Downloads
18,320
import { CoinsIcon, DownloadSimpleIcon, UsersIcon } from '@phosphor-icons/react';
import { Group, Stat } from '@mantine/core';

function Demo() {
  return (
    <Group gap={50}>
      <Stat label="Users" value={92410} thousandSeparator diff={12.4} icon={<UsersIcon size={28} />} />
      <Stat
        label="Revenue"
        value={1340.5}
        prefix="$"
        decimalScale={2}
        fixedDecimalScale
        thousandSeparator
        diff={4.1}
        icon={<CoinsIcon size={28} />}
      />
      <Stat label="Downloads" value={18320} thousandSeparator icon={<DownloadSimpleIcon size={28} />} />
    </Group>
  );
}

Loading state

Set loading prop to display a Skeleton instead of the value and hide the trend indicator:

Active users
Revenue
$
import { Group, Stat } from '@mantine/core';

function Demo() {
  return (
    <Group gap={50}>
      <Stat label="Active users" value={92410} thousandSeparator loading />
      <Stat
        label="Revenue"
        value={1340.5}
        prefix="$"
        decimalScale={2}
        fixedDecimalScale
        thousandSeparator
        loading
      />
    </Group>
  );
}

Animated value

Set animate prop to animate numeric value changes with RollingNumber:

Active users
import { useState } from 'react';
import { Button, Stack, Stat } from '@mantine/core';

function Demo() {
  const [value, setValue] = useState(92410);

  return (
    <Stack align="flex-start">
      <Stat label="Active users" value={value} thousandSeparator animate />
      <Button onClick={() => setValue(Math.round(Math.random() * 100000))}>
        Update value
      </Button>
    </Stack>
  );
}

Countdown

Stat.Countdown displays a live countdown to a target time. value is a Date or a timestamp in milliseconds, keep it stable between renders: a new value restarts the countdown.

format prop accepts dayjs-style tokens:

  • Units absent from the format roll into the leading token: mm:ss displays 62 minutes as 62:00
  • S displays tenths of a second, SS hundredths and SSS milliseconds
  • Literal characters are escaped with square brackets, for example D[d] HH:mm:ss
Sale ends in
03:00:00
Launch in
1d 02:00:00
Round ends
00:59.994
import { useState } from 'react';
import { Group, Stat } from '@mantine/core';

function Demo() {
  const [targets] = useState(() => ({
    sale: Date.now() + 1000 * 60 * 60 * 3,
    launch: Date.now() + 1000 * 60 * 60 * 26,
    round: Date.now() + 1000 * 60,
  }));

  return (
    <Group gap={50}>
      <Stat.Countdown label="Sale ends in" value={targets.sale} />
      <Stat.Countdown label="Launch in" value={targets.launch} format="D[d] HH:mm:ss" />
      <Stat.Countdown label="Round ends" value={targets.round} format="mm:ss.SSS" />
    </Group>
  );
}

onFinish is called once when the target time is reached, onTick is called on every tick with the remaining time in milliseconds:

import { useState } from 'react';
import { Stat } from '@mantine/core';

function Demo() {
  const [target] = useState(() => Date.now() + 1000 * 60 * 15);

  return (
    <Stat.Countdown
      label="Offer expires in"
      value={target}
      format="mm:ss"
      onFinish={() => console.log('Countdown finished')}
      onTick={(remainingMs) => console.log(remainingMs)}
    />
  );
}

Color

Set color prop to change the value color:

import { Stat } from '@mantine/core';

function Demo() {
  return <Stat label="Active users" value={92410} thousandSeparator color="blue" />;
}

Compound components

For full control over the layout, use compound components instead of the shorthand props. Stat.Icon is always placed next to the value, other components are rendered in the order they are declared:

$1,340.50
Total revenue
+12.4% increase
import { Stat } from '@mantine/core';

function Demo() {
  return (
    <Stat>
      <Stat.Value prefix="$">1,340.50</Stat.Value>
      <Stat.Label>Total revenue</Stat.Label>
      <Stat.Diff value={12.4} />
    </Stat>
  );
}

Example: dashboard stat row

Compose several Stat components in a SimpleGrid to build a stat row:

Active users
92,410
+12.4% increase
Revenue
$1,340.50
-4.1% decrease
Orders
2,847
+0.8% increase
import { CoinsIcon, ShoppingCartIcon, UsersIcon } from '@phosphor-icons/react';
import { Paper, SimpleGrid, Stat } from '@mantine/core';

function Demo() {
  return (
    <SimpleGrid cols={{ base: 1, sm: 3 }} w="100%">
      <Paper withBorder p="md" radius="md">
        <Stat label="Active users" value={92410} thousandSeparator diff={12.4} icon={<UsersIcon size={26} />} />
      </Paper>
      <Paper withBorder p="md" radius="md">
        <Stat label="Revenue" value={1340.5} prefix="$" decimalScale={2} fixedDecimalScale thousandSeparator diff={-4.1} icon={<CoinsIcon size={26} />} />
      </Paper>
      <Paper withBorder p="md" radius="md">
        <Stat label="Orders" value={2847} thousandSeparator diff={0.8} icon={<ShoppingCartIcon size={26} />} />
      </Paper>
    </SimpleGrid>
  );
}

Accessibility

  • Stat.Countdown value is not announced on every tick. To announce milestones, render your own live region and update it from onTick.
  • When loading is set, the root element has aria-busy="true".
  • Stat.Diff renders a visually hidden direction text after the delta, screen readers announce +12.4% increase. Use diffLabels prop to translate these texts:
import { Stat } from '@mantine/core';

function Demo() {
  return (
    <Stat
      label="Chiffre d'affaires"
      value={1340}
      diff={12.4}
      diffLabels={{ increase: 'hausse', decrease: 'baisse', neutral: 'stable' }}
    />
  );
}

Styles API

Stat supports the Styles API; you can add styles to any inner element of the component with the classNames prop. Follow the Styles API documentation to learn more.

Monthly revenue
$92,410 USD
+12.4% increase

Component Styles API

Hover or focus a selector to highlight its elements

/*
 * Hover or focus a selector
 * to outline its elements
 */