A meter for a single value: a half-circle arc with the number in the middle, or a linear scale with a gradient and a marker. The color and level caption come from thresholds. It is a server component with no client JavaScript: the fill and the marker position are CSS custom properties, so a new value moves them with a CSS transition, and on first paint the arc grows from zero through @starting-style.
Browser Support
Animates the initial appearance
Mixes gauge and background colors
Preview
Press the button: both views move to the new value.
Installation
Usage
import { Gauge } from "@/components/ui/gauge"
export default function Example() {
return <Gauge value={72} label="Score" />
}Examples
Custom thresholds
Thresholds set where each level starts, its color and caption. The arc is painted with a gradient through the threshold colors. Here a high value is bad, so the colors go the other way.
<Gauge
value={cpu}
label="CPU load"
formatValue={(v) => `${Math.round(v)}%`}
thresholds={[
{ from: 0, color: "var(--primary)", label: "Normal" },
{ from: 60, color: "color-mix(in oklch, var(--destructive) 55%, var(--primary))", label: "Busy" },
{ from: 85, color: "var(--destructive)", label: "Critical" },
]}
/>Linear scale
variant="bar" draws a gradient built from the threshold colors. One threshold gives a solid bar.
<Gauge
variant="bar"
value={23}
label="Market mood"
thresholds={[
{ from: 0, color: "var(--destructive)", label: "Fear" },
{ from: 45, color: "var(--muted-foreground)", label: "Neutral" },
{ from: 60, color: "var(--primary)", label: "Greed" },
]}
/>
<Gauge
variant="bar"
value={412}
max={512}
showLevel={false}
showRange
formatValue={(v) => `${Math.round(v)} GB`}
thresholds={[{ from: 0, color: "var(--primary)" }]}
/>Compact
The number scales with the gauge width, so small gauges fit in tables and cards.
<Gauge value={64} thickness={10} showLevel={false} className="w-28" />Props
| Prop | Type | Default | Description |
|---|---|---|---|
| value | number | - | Current value, clamped to min and max |
| min | number | 0 | Scale minimum |
| max | number | 100 | Scale maximum |
| variant | "arc" | "bar" | "arc" | Arc or linear scale |
| thresholds | { from: number; color: string; label?: string }[] | - | Levels: where each starts, its color and caption. By default three levels from destructive to primary |
| label | string | - | Accessible name of the meter |
| showValue | boolean | true | Show the number |
| showLevel | boolean | true | Show the level caption |
| showRange | boolean | false | Show min and max under the scale |
| formatValue | (value: number) => string | Math.round | Formats the number on screen |
| valueText | (value: number, level?: string) => string | - | Builds aria-valuetext. By default the number and the level |
| duration | number | 700 | Transition duration of the arc and the marker in ms |
| thickness | number | 20 / 10 | Arc stroke or bar height in px |
| className | string | - | Additional CSS classes |
Features
- Two views: half-circle arc or linear scale with a marker
- Thresholds: color and level caption change with the value
- Smooth motion: the arc and the marker ease to a new value, instantly with reduced motion
- No JavaScript: works in Server Components, nothing to hydrate
- Accessible: role="meter" with aria-valuenow, min, max and aria-valuetext