GooseUI

Components

Gauge

New

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

@starting-style

Animates the initial appearance

Your browser:
color-mix()

Mixes gauge and background colors

Your browser:

Preview

Press the button: both views move to the new value.

72Medium
0100
72Medium
0100

Installation

npx shadcn@latest add @gooseui/gauge
pnpm dlx shadcn@latest add @gooseui/gauge
yarn dlx shadcn@latest add @gooseui/gauge
bunx --bun shadcn@latest add @gooseui/gauge

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.

58%Normal
<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.

23Fear
412 GB
0 GB512 GB
<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.

32
64
91
<Gauge value={64} thickness={10} showLevel={false} className="w-28" />

Props

PropTypeDefaultDescription
valuenumber-Current value, clamped to min and max
minnumber0Scale minimum
maxnumber100Scale 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
labelstring-Accessible name of the meter
showValuebooleantrueShow the number
showLevelbooleantrueShow the level caption
showRangebooleanfalseShow min and max under the scale
formatValue(value: number) => stringMath.roundFormats the number on screen
valueText(value: number, level?: string) => string-Builds aria-valuetext. By default the number and the level
durationnumber700Transition duration of the arc and the marker in ms
thicknessnumber20 / 10Arc stroke or bar height in px
classNamestring-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