Meter
A reading inside a known range, like a context window or a credit balance, with a label, a formatted value and a fill that can turn to a status tone.
Installation
npx shadcn@latest add "@aiellie/meter"shadcn needs the @aiellie registry in components.json first. npx aiellie add meter adds it on its first run, then installs the same way.
Meter shows how much of something is used: a context window, monthly credits, storage. It is Base UI's meter, so it is a measurement rather than a progress bar, and screen readers read it as one. A label and a value sit over a thin track, and a tone turns the fill green or red when the amount means something.
Getting started
Add a meter with its label and value
valueis out ofmax, 100 by default. The track is drawn for you; the label and the value are children, so you choose what shows.components/credits.tsximport { Meter, MeterLabel, MeterValue } from "@/components/ui/meter" export function Credits({ used }: { used: number }) { return ( <Meter value={used}> <MeterLabel>Monthly credits</MeterLabel> <MeterValue /> </Meter> ) }Format the value
formattakesIntl.NumberFormatoptions.MeterValuetakes a function for text of your own, andgetAriaValueTextsays the same to a screen reader.<Meter value={64_000} max={200_000} format={{ notation: "compact" }} getAriaValueText={(tokens) => `${tokens} of 200K tokens`} > <MeterLabel>Context window</MeterLabel> <MeterValue>{(tokens) => `${tokens} / 200K`}</MeterValue> </Meter>
Anatomy
<div data-slot="meter" data-tone="default" role="meter">
<span data-slot="meter-label" />
<span data-slot="meter-value" /> {/* pushed to the end */}
<div data-slot="meter-track"> {/* added for you, under them */}
<div data-slot="meter-indicator" />
</div>
</div>The track is 4px tall on muted, and the fill is foreground, destructive, or emerald for success, since a shadcn theme has no success token. Only the fill changes with the tone, so the label stays readable. A change of value slides the fill over 280ms.
Examples
A tone that follows the value
Turn the fill red once the window is nearly full.
Without a label
With no children, give the meter an aria-label so it still has a name.
<Meter value={40} aria-label="Storage used" className="w-24" />API reference
Meter
Base UI's Meter.Root, with the track inside it.
| Prop | Type | Default | Description |
|---|---|---|---|
value | number | required | How much is used. |
min / max | number | 0 / 100 | The range. |
tone | "default" | "success" | "destructive" | "default" | Recolours the fill only. |
format | Intl.NumberFormatOptions | How MeterValue and screen readers write the number. | |
getAriaValueText | (formatted: string, value: number) => string | What a screen reader says for the value. | |
className | string | Merged onto the root. |
Parts
| Export | Renders | Notes |
|---|---|---|
MeterLabel | span | Its name, in muted-foreground. |
MeterValue | span | The formatted value at the end. Takes a function of the formatted value for text of your own. |
MeterTrack / MeterIndicator | div | The track and its fill. Meter adds them; export them to build a meter of your own from Base UI's root. |