Stats

Stats

New Orders 128 12.5%
Items Ordered 342 8.1%
Returns 6 25.0%
Time to Fulfill 1.4 Days
<div class="card">
<div class="stat-group">
<div class="stat">
<span>New Orders</span>
<strong>128</strong>
<span data-trend="up"><i class="icon icon-arrow-up" aria-hidden="true"></i>12.5%</span>
</div>
<div class="stat">
<span>Items Ordered</span>
<strong>342</strong>
<span data-trend="up"><i class="icon icon-arrow-up" aria-hidden="true"></i>8.1%</span>
</div>
<div class="stat">
<span>Returns</span>
<strong>6</strong>
<span data-trend="down"><i class="icon icon-arrow-down" aria-hidden="true"></i>25.0%</span>
</div>
<div class="stat">
<span>Time to Fulfill</span>
<strong>1.4 Days</strong>
</div>
</div>
</div>

A stat is a label, a value and an optional change

The first span is the label and the strong is the value. A span with data-trend says how it changed.

<div class="stat">
<span>New Orders</span>
<strong>128</strong>
<span data-trend="up"><i class="icon icon-arrow-up" aria-hidden="true"></i>12.5%</span>
</div>

One stat in a card

Net Revenue $48,210.00 4.2%
<div class="card max-w-xs">
<div class="stat">
<span>Net Revenue</span>
<strong>$48,210.00</strong>
<span data-trend="up"><i class="icon icon-arrow-up" aria-hidden="true"></i>4.2%</span>
</div>
</div>

A link to the records behind the figure, and an info button on the label

data-trend="up" is the success colour, "down" the destructive colour, and no value is muted

Rising 128 12.5%
Falling 96 25.0%
Unchanged 40 0.0%
No comparison 7
<div class="card max-w-2xl">
<div class="stat-group">
<div class="stat">
<span>Rising</span>
<strong>128</strong>
<span data-trend="up"><i class="icon icon-arrow-up" aria-hidden="true"></i>12.5%</span>
</div>
<div class="stat">
<span>Falling</span>
<strong>96</strong>
<span data-trend="down"><i class="icon icon-arrow-down" aria-hidden="true"></i>25.0%</span>
</div>
<div class="stat">
<span>Unchanged</span>
<strong>40</strong>
<span data-trend>0.0%</span>
</div>
<div class="stat">
<span>No comparison</span>
<strong>7</strong>
</div>
</div>
</div>

data-reverse on the stat swaps the colours, where a rise is bad news

Returns 14 40.0%
Time to Fulfill 0.9 Days 18.0%
<div class="card max-w-md">
<div class="stat-group">
<div class="stat" data-reverse>
<span>Returns</span>
<strong>14</strong>
<span data-trend="up"><i class="icon icon-arrow-up" aria-hidden="true"></i>40.0%</span>
</div>
<div class="stat" data-reverse>
<span>Time to Fulfill</span>
<strong>0.9 Days</strong>
<span data-trend="down"><i class="icon icon-arrow-down" aria-hidden="true"></i>18.0%</span>
</div>
</div>
</div>

aria-busy="true" shows the stat's spinner in place of the value while it loads

New Orders 128 12.5%
Items Ordered 342 8.1%
<div class="flex flex-col items-start gap-4">
<div class="card max-w-md self-stretch">
<div class="stat-group" id="demo-stat-loading">
<div class="stat" aria-busy="true">
<span>New Orders</span>
<strong>128</strong>
<span data-trend="up"><i class="icon icon-arrow-up" aria-hidden="true"></i>12.5%</span>
<span class="spinner" data-size="xs" role="status" aria-label="Loading"></span>
</div>
<div class="stat" aria-busy="true">
<span>Items Ordered</span>
<strong>342</strong>
<span data-trend="up"><i class="icon icon-arrow-up" aria-hidden="true"></i>8.1%</span>
<span class="spinner" data-size="xs" role="status" aria-label="Loading"></span>
</div>
</div>
</div>
<button type="button" class="btn" data-variant="outline" data-size="sm" onclick="document.querySelectorAll('#demo-stat-loading .stat').forEach((stat) => stat.toggleAttribute('aria-busy') && stat.setAttribute('aria-busy', 'true'))">Toggle loading</button>
</div>

A control beside the group stays outside it, so its menu is not cut off

New Orders 128 12.5%
Items Ordered 342 8.1%
Returns 6 25.0%
Fulfilled Orders 117 9.3%
Time to Fulfill 1.4 Days
Delivered Orders 102 3.0%
<div class="card flex-row">
<div id="demo-stat-period" class="dropdown self-center px-3">
<button type="button" id="demo-stat-period-trigger" aria-haspopup="menu" aria-controls="demo-stat-period-menu" aria-expanded="false" class="btn" data-variant="ghost" data-size="sm">30 Days<i class="icon icon-chevron-down" aria-hidden="true"></i></button>
<div id="demo-stat-period-popover" data-popover aria-hidden="true" class="w-36">
<div role="menu" id="demo-stat-period-menu" aria-labelledby="demo-stat-period-trigger">
<div role="menuitemradio" aria-checked="false">Today</div>
<div role="menuitemradio" aria-checked="false">7 Days</div>
<div role="menuitemradio" aria-checked="true">30 Days</div>
<div role="menuitemradio" aria-checked="false">60 Days</div>
<div role="menuitemradio" aria-checked="false">90 Days</div>
</div>
</div>
</div>
<div class="stat-group border-s">
<div class="stat">
<span>New Orders</span>
<strong>128</strong>
<span data-trend="up"><i class="icon icon-arrow-up" aria-hidden="true"></i>12.5%</span>
</div>
<div class="stat">
<span>Items Ordered</span>
<strong>342</strong>
<span data-trend="up"><i class="icon icon-arrow-up" aria-hidden="true"></i>8.1%</span>
</div>
<div class="stat">
<span>Returns</span>
<strong>6</strong>
<span data-trend="down"><i class="icon icon-arrow-down" aria-hidden="true"></i>25.0%</span>
</div>
<div class="stat">
<span>Fulfilled Orders</span>
<strong>117</strong>
<span data-trend="up"><i class="icon icon-arrow-up" aria-hidden="true"></i>9.3%</span>
</div>
<div class="stat">
<span>Time to Fulfill</span>
<strong>1.4 Days</strong>
</div>
<div class="stat">
<span>Delivered Orders</span>
<strong>102</strong>
<span data-trend="up"><i class="icon icon-arrow-up" aria-hidden="true"></i>3.0%</span>
</div>
</div>
</div>

Linked small stats beside a page title: one destructive, one still loading

<header class="page-header">
<h1>Orders</h1>
<div class="page-header-action">
<a href="#" class="stat" data-size="sm" data-variant="destructive">
<span>Rejected</span>
<strong>24</strong>
</a>
<a href="#" class="stat" data-size="sm">
<span>On Hold</span>
<strong>2</strong>
</a>
<a href="#" class="stat" data-size="sm">
<span>Unfulfilled</span>
<strong>6</strong>
</a>
<a href="#" class="stat" data-size="sm" aria-busy="true">
<span>Processing</span>
<strong>0</strong>
<span class="spinner" data-size="xs" role="status" aria-label="Loading"></span>
</a>
<a href="#" class="btn">Create Order</a>
</div>
</header>

Stats that pick what a chart shows: buttons, the picked one aria-pressed="true"

<div class="card">
<div class="stat-group" data-even>
<button type="button" class="stat" aria-pressed="false" onclick="this.parentElement.querySelectorAll('.stat').forEach((stat) => stat.setAttribute('aria-pressed', String(stat === this)))">
<span>New Sessions</span>
<strong>4,812</strong>
<span data-trend="up"><i class="icon icon-arrow-up" aria-hidden="true"></i>12.4%</span>
</button>
<button type="button" class="stat" aria-pressed="false" onclick="this.parentElement.querySelectorAll('.stat').forEach((stat) => stat.setAttribute('aria-pressed', String(stat === this)))">
<span>Orders</span>
<strong>238</strong>
<span data-trend="down"><i class="icon icon-arrow-down" aria-hidden="true"></i>3.2%</span>
</button>
<button type="button" class="stat" aria-pressed="true" onclick="this.parentElement.querySelectorAll('.stat').forEach((stat) => stat.setAttribute('aria-pressed', String(stat === this)))">
<span>Sales</span>
<strong>$21,402.62</strong>
<span data-trend="down"><i class="icon icon-arrow-down" aria-hidden="true"></i>5.7%</span>
</button>
</div>
</div>

Parts and attributes

Part What it does
.stat One figure. A div; an a when the whole stat is a link (its value takes the primary colour); or a button when it picks what something else shows, such as a chart's metric.
aria-pressed="true" On a button stat: the one picked. It is shaded.
span, first child The label. Cut with an ellipsis when it does not fit.
strong The value, with figures of equal width.
span[data-trend] The change, right aligned on the value's row: up, down, or no value for unchanged. An icon goes before its text.
data-reverse On the stat: a rise is the destructive colour and a fall the success colour.
data-variant="destructive" On the stat: the label and the value take the destructive colour, for a count that is a problem.
aria-busy="true" On the stat: hides the value and the change and shows the stat's spinner.
data-size="sm" On the stat: compact and centred, for beside a page title.
data-even On the group: every stat the same width while the group is wide, but never narrower than its text. For a group whose stats always fit on one row.
.stat-group A row of stats with a line between them. A narrow group of four or more is laid out in four columns, then two.