Skip to content

React Meter

A glass React meter for a level inside a known range, such as storage, battery or password strength, that is spoken as well as colored.

npx shadcn@latest add https://lokendra-builds.github.io/sheenui/r/meter.json
Storage used

Plenty of room left.

x
  • Meter
  • getMeterLevel
  • defaultMeterLevelLabels
  • +1 more

Levels

Storage: lower is better (optimum 0), so it goes amber past 70% and red past 90%. Battery: higher is better. CPU updates live; the fill springs and the number counts with it.

Storage used
72
Storage

46.1 GB of 64 GB used

x
Battery
x
CPU
x

Files to copy

5 folders · 5 files · 4 packages
From theme/src/
  • components/meter/
  • hooks/{use-media-query.ts, use-preferences.ts}
  • motion/tokens.ts
  • lib/{cn.ts, math.ts}
  • styles/
shadcn CLI
npx shadcn@latest add https://lokendra-builds.github.io/sheenui/r/meter.jsonRegistry item: meter. The styles need the Tailwind v4 glass UI setup.
Packages
pnpm add @base-ui/react clsx motion tailwind-merge

Segmented and custom values

variant=segmented draws cells, like a battery or signal meter. format / valueText change the number; levelLabels rename the levels.

Password strength
x
Bandwidth this month
x
Signal
x

Props

PropTypeDefaultDescription
maxnumber100Largest value of the scale; a value above it is clamped.
minnumber0Smallest value of the scale; a value below it is clamped.
labelReactNodeNoneVisible label (also the meter's accessible name). Without it, pass aria-label.
descriptionReactNodeNoneHelp text under the bar, e.g. "4.2 GB of 16 GB used". Linked with aria-describedby.
lownumberNoneUpper bound of the low region. With high, enables good / warning / critical colouring.
highnumberNoneSets the lower bound of the high region.
optimumnumberthe middle of the range (HTML <meter> rules)Sets where the best value lies.
valueTextReactNode | ((formatted: string, value: number) => ReactNode)Base UI's formatted valueThe value text on the right: Base UI's formatted value (percentage of the range, or format applied to the value). A function receives (formatted, value). false hides it.
showLevelbooleanfalseWrite the level ("Good", "Warning", "Critical") next to the value.
levelLabelsPartial<Record<MeterLevel, string>>NoneWords for each level (spoken in aria-valuetext, shown with showLevel).
variant"bar" | "segmented""bar"bar (default): one continuous fill. segmented: a row of cells, like a battery or signal meter.
segmentsnumber10Sets the number of cells for the segmented variant.
size"sm" | "md" | "lg""md"Thickness of the bar: "sm" (6px), "md" (10px, default) or "lg" (16px).
showThresholdsbooleanon for the bar variantSmall ruler ticks under the bar at low and high.
classNamestringNoneAdds extra classes to the outer element.
valuenumberNoneRequired. Clamped to [min, max] (NaN falls back to min).
format / localeIntl.NumberFormatOptions / stringNoneNumber formatting (Intl), also used for aria-valuetext.
getAriaValueText(formatted, value) => stringNoneGives full control over the spoken value.

Keyboard

KeysAction
TabNot focusable: a meter is a read-out, not a control.

Accessibility

  • role="meter" named by label (or aria-label), described by description, with aria-valuenow, aria-valuemin and aria-valuemax.
  • The level (critical, suboptimal, optimum) is part of the spoken value (aria-valuetext) and, with showLevel, written next to the value, so color is never the only signal.
  • Use variant="segmented" for battery- or signal-style read-outs; the same spoken value applies.

All exports on this page

  • Meter — Meter: a measurement within a known range (disk usage, battery, password strength, CPU load).
  • defaultMeterLevelLabels — Default words for each MeterLevel (Good, Warning, Critical).
  • getMeterLevel — Which region the value falls in, by the HTML <meter> algorithm.

When to use Meter

  • Use it as a storage usage bar, such as 41 GB of 64 GB, where lower is better and the bar turns amber past 70 percent and red past 90 percent using low, high and optimum.
  • Use it for a battery or signal read-out with variant="segmented", which draws cells like a battery icon, and for password strength with levelLabels renamed to Weak and Strong.
  • Use it for a live value such as CPU load, where the fill springs to the new level and the number counts with it.
  • Skip it when the value shows progress toward completion of a task; Progress is the right component for uploads and steps, because a meter describes a level in a range rather than how far along something is.
  • Pair it with Badge to repeat the level in words, Tooltip for the exact value, and GlassCard to group several meters in a dashboard.

Frequently asked questions

Guides that cover it

67 components pages in all: browse them on All components.

By Lokendra Singh Rathore (GitHub, opens in a new tab). Published , updated .