Stats cards
A responsive row of metric cards with a value, an icon and the change since the last period.
Installation
bash
npx bootcn add stats-cardsbash
pnpm dlx bootcn add stats-cardsbash
yarn dlx bootcn add stats-cardsbash
bunx --bun bootcn add stats-cardsThe CLI also installs the design tokens and these blocks and components: none. It prints the <link> and <script> tags to add to your layout.
Usage
Replace the labels, values and changes with your data. Add or remove bootcn-stats__card articles; the grid fits as many as the width allows.
Format numbers on the server for the user's locale. Values use tabular figures so columns of numbers line up.
Accessibility
- A visually hidden
<h2>names the group; each card has an<h3>label, so screen-reader users can jump between metrics. - The change is text (
+20.1%,−4.3%), not colour alone; the arrow icons are decorative. - Up and down use Bootstrap's
*-text-emphasiscolours, which keep 4.5:1 contrast in both themes.
Dependencies
- Bootstrap 5.3+ CSS.
themes/tokens/tokens.css.
Source
The exact files the CLI installs (stats-cards@1.1.0). View on GitHub · Report an issue
html
<section class="bootcn-stats" aria-labelledby="bootcn-stats-title">
<h2 class="visually-hidden" id="bootcn-stats-title">Key metrics</h2>
<div class="bootcn-stats__grid">
<article class="bootcn-stats__card">
<div class="bootcn-stats__head">
<h3 class="bootcn-stats__label">Revenue</h3>
<svg
class="bootcn-stats__icon"
width="16"
height="16"
viewBox="0 0 24 24"
fill="none"
stroke="currentColor"
stroke-width="2"
stroke-linecap="round"
stroke-linejoin="round"
aria-hidden="true"
focusable="false"
>
<path d="M12 3v18" />
<path d="M17 7c-1-1.5-3-2-5-2-3 0-4 1.5-4 3s1 2.5 4 3 4 1.5 4 3-1 3-4 3c-2 0-4-.5-5-2" />
</svg>
</div>
<p class="bootcn-stats__value">€45,231.89</p>
<p class="bootcn-stats__change bootcn-stats__change--up">
<svg
class="bootcn-icon"
width="16"
height="16"
viewBox="0 0 24 24"
fill="none"
stroke="currentColor"
stroke-width="2"
stroke-linecap="round"
stroke-linejoin="round"
aria-hidden="true"
focusable="false"
>
<path d="M7 14l5-5 5 5" />
</svg>
<span>+20.1%</span> since last month
</p>
</article>
<article class="bootcn-stats__card">
<div class="bootcn-stats__head">
<h3 class="bootcn-stats__label">Subscriptions</h3>
<svg
class="bootcn-stats__icon"
width="16"
height="16"
viewBox="0 0 24 24"
fill="none"
stroke="currentColor"
stroke-width="2"
stroke-linecap="round"
stroke-linejoin="round"
aria-hidden="true"
focusable="false"
>
<circle cx="9" cy="8" r="4" />
<path d="M2 21c0-4 3-7 7-7s7 3 7 7" />
<path d="M17 4a4 4 0 0 1 0 8" />
<path d="M22 21c0-3-2-6-5-7" />
</svg>
</div>
<p class="bootcn-stats__value">2,350</p>
<p class="bootcn-stats__change bootcn-stats__change--up">
<svg
class="bootcn-icon"
width="16"
height="16"
viewBox="0 0 24 24"
fill="none"
stroke="currentColor"
stroke-width="2"
stroke-linecap="round"
stroke-linejoin="round"
aria-hidden="true"
focusable="false"
>
<path d="M7 14l5-5 5 5" />
</svg>
<span>+180</span> since last month
</p>
</article>
<article class="bootcn-stats__card">
<div class="bootcn-stats__head">
<h3 class="bootcn-stats__label">Orders</h3>
<svg
class="bootcn-stats__icon"
width="16"
height="16"
viewBox="0 0 24 24"
fill="none"
stroke="currentColor"
stroke-width="2"
stroke-linecap="round"
stroke-linejoin="round"
aria-hidden="true"
focusable="false"
>
<circle cx="9" cy="20" r="1" />
<circle cx="18" cy="20" r="1" />
<path d="M2 3h3l3 12h11l2-8H6" />
</svg>
</div>
<p class="bootcn-stats__value">12,234</p>
<p class="bootcn-stats__change bootcn-stats__change--down">
<svg
class="bootcn-icon"
width="16"
height="16"
viewBox="0 0 24 24"
fill="none"
stroke="currentColor"
stroke-width="2"
stroke-linecap="round"
stroke-linejoin="round"
aria-hidden="true"
focusable="false"
>
<path d="M7 10l5 5 5-5" />
</svg>
<span>−4.3%</span> since last month
</p>
</article>
<article class="bootcn-stats__card">
<div class="bootcn-stats__head">
<h3 class="bootcn-stats__label">Active now</h3>
<svg
class="bootcn-stats__icon"
width="16"
height="16"
viewBox="0 0 24 24"
fill="none"
stroke="currentColor"
stroke-width="2"
stroke-linecap="round"
stroke-linejoin="round"
aria-hidden="true"
focusable="false"
>
<path d="M3 12h4l3 8 4-16 3 8h4" />
</svg>
</div>
<p class="bootcn-stats__value">573</p>
<p class="bootcn-stats__change bootcn-stats__change--up">
<svg
class="bootcn-icon"
width="16"
height="16"
viewBox="0 0 24 24"
fill="none"
stroke="currentColor"
stroke-width="2"
stroke-linecap="round"
stroke-linejoin="round"
aria-hidden="true"
focusable="false"
>
<path d="M7 14l5-5 5 5" />
</svg>
<span>+201</span> since last month
</p>
</article>
</div>
</section>css
/* One column on phones, two on tablets, four on wide screens. */
.bootcn-stats__grid {
display: grid;
grid-template-columns: repeat(auto-fit, minmax(min(100%, 13rem), 1fr));
gap: 1rem;
}
.bootcn-stats__card {
padding: var(--bootcn-card-padding);
border: var(--bootcn-border-width) solid var(--bootcn-border-color);
border-radius: var(--bootcn-radius-xl);
background-color: var(--bootcn-background);
box-shadow: var(--bootcn-shadow-sm);
}
.bootcn-stats__head {
display: flex;
align-items: center;
justify-content: space-between;
gap: 0.5rem;
margin-bottom: 0.5rem;
}
.bootcn-stats__label {
margin: 0;
color: var(--bs-secondary-color);
font-size: 0.875rem;
font-weight: 500;
}
.bootcn-stats__icon {
color: var(--bs-secondary-color);
}
.bootcn-stats__value {
margin: 0;
color: var(--bs-emphasis-color);
font-size: 1.5rem;
font-weight: 700;
letter-spacing: -0.025em;
line-height: 1.2;
font-variant-numeric: tabular-nums;
}
.bootcn-stats__change {
display: flex;
align-items: center;
gap: 0.25rem;
margin: 0.25rem 0 0;
color: var(--bs-secondary-color);
font-size: 0.8125rem;
}
.bootcn-stats__change--up span {
color: var(--bs-success-text-emphasis);
font-weight: 600;
}
.bootcn-stats__change--down span {
color: var(--bs-danger-text-emphasis);
font-weight: 600;
}
.bootcn-stats__change--up .bootcn-icon {
color: var(--bs-success-text-emphasis);
}
.bootcn-stats__change--down .bootcn-icon {
color: var(--bs-danger-text-emphasis);
}
