Marketing sectionsStatsGrid
Searchastronomic.dev# StatsGrid
To show a few results as large numbers on the open page, each under a hairline.
Static: no JavaScript.
## Usage
```astro
import StatsGrid from "@astronomic-dev/ui/components/StatsGrid.astro";
```
## Examples
### Results
An open grid on the page, a hairline above each stat. As many columns as fit, each at least 9rem: one on a 320px phone, two from about a 370px phone, four on a wide page.
```astro
---
import StatsGrid from "@astronomic-dev/ui/components/StatsGrid.astro";
const stats = [
{ value: "+38%", label: "Inquiries in the first quarter" },
{ value: "1.2s", label: "Largest paint on mobile" },
{ value: "14", label: "Editors trained" },
{ value: "0", label: "Support calls since launch" },
];
---
<div class="mx-auto max-w-6xl px-6 py-16">
<StatsGrid items={stats} />
</div>
```
### In a narrow column
The same stats full width and in a 24rem column. Each value sizes to its own stat, so it is smaller in the column; the long value stays on one line, never split mid-number, and fits its stat.
```astro
---
import StatsGrid from "@astronomic-dev/ui/components/StatsGrid.astro";
import { displayType } from "@astronomic-dev/ui/lib/display.ts";
const stats = [
{ value: "+38%", label: "Inquiries in the first quarter" },
{ value: "1.2s", label: "Largest paint on mobile" },
{ value: "14", label: "Editors trained" },
{ value: "12,500,000+", label: "Page views in the first year" },
];
---
<div class="mx-auto grid max-w-6xl gap-blocks px-6 py-16">
<div data-wide class="grid gap-blocks">
<h2 class={`m-0 text-title text-balance ${displayType}`}>Results</h2>
<StatsGrid items={stats} />
</div>
<div data-narrow class="grid max-w-sm gap-blocks">
<h2 class={`m-0 text-title text-balance ${displayType}`}>In a narrow column</h2>
<StatsGrid items={stats} />
</div>
</div>
```
## Props
### StatsGrid
| Prop | Type | Default | Description |
| --- | --- | --- | --- |
| `items` | `StatItem[]` | None | Required. The stats: { value, label, text? } (StatItem). value shows large, in the stat role, sized to its own item, on one line (never broken mid-number): every value in the list takes the size at which the widest one fits its stat, so short values come out large and 12,500,000+ still fits a 9rem stat; text is one short line under the label. Only these fields render, so a CMS entry's other fields never reach the page. |
| `heading` | `string` | None | The section heading, in the title role in display type. Without it, and without label, a plain <div> holds only the list. |
| `emphasis` | `boolean` | `false` | Turn one *phrase* in the heading into <em>: exactly two asterisks around text with no space inside, as in "Built for *the long run*". Any other asterisks show as typed. Off by default, so the heading shows as typed. How the <em> looks is the theme's. |
| `mark` | `string` | None | A short mark after the heading, such as "(12)" or "©2026", in small muted type. It sits beside the heading, outside it, so the heading's name stays plain. Shown only with a heading. |
| `markLabel` | `string` | None | What the mark says to a screen reader, such as "12 projects": the mark is then hidden from screen readers and this is read in its place. Without it, the mark is read as written. |
| `text` | `string` | None | One or two sentences under the heading, in the lead role, muted. Shown only with a heading. |
| `headingTag` | `"h2" \| "h3" \| "h4"` | `"h2"` | The heading element. |
| `label` | `string` | None | Names the stats when there is no heading: the root is then a <section aria-label>. Ignored with a heading. |
| `class` | `string` | None | More classes for the root (the <section>, or the <div> without a heading or label), merged with cn(), so yours win on conflicts. The root is a named size container (inline-size containment): in a shrink-to-fit parent (inline-flex, a float, fit-content) it collapses, so give it a width there. |
| `align` | `"start" \| "center"` | `"start"` | The header and each stat at the start, or centered. |
| Slot | Description |
| --- | --- |
| `eyebrow` | A short line above the heading, such as a Badge. Shown only with a heading. |
Any other attribute goes on the <section>, or on the <div> without a heading or label.
## Accessibility
- With a heading, renders a <section> named by it, so it is a region landmark. The heading id is unique on the page.
- Without a heading or a label, renders a plain <div>. Put your own heading above it.
- Each stat is a label (<dt>) and a value (<dd>), the label first, so a screen reader reads 'Projects shipped: 120'. With label and no heading, the stats are a region named by it.
- The value is text, never counted up: what a screen reader reads is what shows.
- An empty items list renders an empty list: leave the section out when there is nothing to show.
StatsGrid
FreeTo show a few results as large numbers on the open page, each under a hairline.
- File
- StatsGrid.astro
- Group
- Marketing sections
- Kind
- Static: no JavaScript
- Examples
- 2
Examples
Drag the orange handle to set the width. Frames get real breakpoints.
- Static
- Interactive
- Framed
Results
An open grid on the page, a hairline above each stat. As many columns as fit, each at least 9rem: one on a 320px phone, two from about a 370px phone, four on a wide page.
This preview did not load.
main.astro
examples/statsgrid/main.astro
---
import StatsGrid from "@astronomic-dev/ui/components/StatsGrid.astro";
const stats = [
{ value: "+38%", label: "Inquiries in the first quarter" },
{ value: "1.2s", label: "Largest paint on mobile" },
{ value: "14", label: "Editors trained" },
{ value: "0", label: "Support calls since launch" },
];
---
<div class="mx-auto max-w-6xl px-6 py-16">
<StatsGrid items={stats} />
</div>In a narrow column
The same stats full width and in a 24rem column. Each value sizes to its own stat, so it is smaller in the column; the long value stays on one line, never split mid-number, and fits its stat.
This preview did not load.
narrow.astro
examples/statsgrid/narrow.astro
---
import StatsGrid from "@astronomic-dev/ui/components/StatsGrid.astro";
import { displayType } from "@astronomic-dev/ui/lib/display.ts";
const stats = [
{ value: "+38%", label: "Inquiries in the first quarter" },
{ value: "1.2s", label: "Largest paint on mobile" },
{ value: "14", label: "Editors trained" },
{ value: "12,500,000+", label: "Page views in the first year" },
];
---
<div class="mx-auto grid max-w-6xl gap-blocks px-6 py-16">
<div data-wide class="grid gap-blocks">
<h2 class={`m-0 text-title text-balance ${displayType}`}>Results</h2>
<StatsGrid items={stats} />
</div>
<div data-narrow class="grid max-w-sm gap-blocks">
<h2 class={`m-0 text-title text-balance ${displayType}`}>In a narrow column</h2>
<StatsGrid items={stats} />
</div>
</div>Minimal · Light