<!-- generated by scripts/gen-docs.mjs from docs/system/meter.md. Edit the source and rerun. -->
# Meter

## Description
Shows how much of a fixed allowance is used, such as seats on a plan or requests against a limit, as a thin bar that fills toward its limit with the amount written beside it.

`import { Meter, MeterLabel, MeterValue } from "@/components/cobalt/ui/meter"`, source `registry/cobalt/ui/meter.tsx`, status `ready-with-gaps`.
Foundation: `Base UI Meter`. Traps checked: `trap/color-only-status`, `trap/numbers-shift`, `trap/loading-layout-shift` (n/a: the bar is drawn at its final height of 8px and a value change only moves the fill inside the track), `trap/motion-layout-property` (n/a: the fill does not transition), `trap/reduced-motion-ignored` (n/a: nothing moves), `trap/live-region-double` (n/a: no live region; a change is not announced), `trap/demo-on-timers` (n/a: every example holds fixed data), `trap/illustration-announced` (n/a: the bar is the meter itself, and the value text is `aria-hidden` because the meter's `aria-valuetext` carries it), `trap/loop-offscreen` (n/a: nothing loops).

### Foundation
| Given by the foundation | Added by the team |
|---|---|
| Base UI `Meter`: `Root` with `role="meter"`, `aria-valuenow`, `aria-valuemin`, `aria-valuemax` and `aria-valuetext`, `aria-labelledby` wired to `Label`, a `Track`, and `getAriaValueText` | `Meter` draws the fill itself instead of using the primitive's indicator: a span from top to bottom of the 8px track (`h-2 rounded-full bg-muted`) at the value's share of the range, the accent (`bg-primary`) up to `high`, so it follows the colour the host or the reader picks as Progress does, and `bg-bad` from `high` up; `aria-valuetext` and the visible `MeterValue` read the same words, "8 of 10" or "9,420 of 10,000", through `formatValue` from `chart-math.ts`, so the amount is written and colour is never the only cue; a value past `max` fills the track and still reads its real figure, "140 of 100", while the primitive holds `aria-valuenow` to the range; a value that is not a number leaves the fill empty and reads "Unknown of 10"; the label takes the room beside the value and wraps there, the value `tabular-nums` at the row's end; `MeterValue` is `aria-hidden`, so the meter's own value text is the only one read |

## Examples
Seats used on a plan, as a share of what the plan allows.

Real uses, 0 call sites (`rg -n "<Meter\b" app registry docs/system/examples --glob '!docs/system/examples/meter/*'`): the showcase chrome renders no Meter of its own, and the examples folder does not count.

Uses inside the registry: none. `registry/cobalt/ui/meter.test.tsx` renders it for the tests.

### Example files
| File | Covers | Caption |
|---|---|---|
| `docs/system/examples/meter/default.tsx` | default | Seats used on a plan, as a share of what the plan allows |
| `docs/system/examples/meter/state-high.tsx` | state:high | Past its high mark the fill turns the bad colour, and the value says by how much |
| `docs/system/examples/meter/in-card.tsx` | composition:Card | A plan's allowances in a card, each a meter with its own limit |

Example: Seats used on a plan, as a share of what the plan allows (`docs/system/examples/meter/default.tsx`)

```tsx
import { Meter, MeterLabel, MeterValue } from "@/components/cobalt/ui/meter";

export default function Example() {
  return (
    <Meter className="w-full max-w-sm" value={8} max={10} high={10}>
      <MeterLabel>Seats</MeterLabel>
      <MeterValue />
    </Meter>
  );
}
```

Example: A plan's allowances in a card, each a meter with its own limit (`docs/system/examples/meter/in-card.tsx`)

```tsx
import { Card, CardContent, CardHeader, CardTitle } from "@/components/cobalt/ui/card";
import { Meter, MeterLabel, MeterValue } from "@/components/cobalt/ui/meter";

const allowances = [
  { label: "Seats", value: 8, max: 10, high: 10 },
  { label: "Saved searches", value: 12, max: 50, high: 45 },
  { label: "Exports this month", value: 6240, max: 10000, high: 9000 },
];

export default function Example() {
  return (
    <Card className="w-full max-w-sm">
      <CardHeader>
        <CardTitle render={<h2 />}>Your plan</CardTitle>
      </CardHeader>
      <CardContent className="flex flex-col gap-5">
        {allowances.map((allowance) => (
          <Meter key={allowance.label} value={allowance.value} max={allowance.max} high={allowance.high}>
            <MeterLabel>{allowance.label}</MeterLabel>
            <MeterValue />
          </Meter>
        ))}
      </CardContent>
    </Card>
  );
}
```

## Variants
Not applicable: Meter has no variant axis. The track is 8px tall at the width of its container, and the fill is the accent until `high`.

## States
| State | Trigger | What the user can do | Shown by, besides color | Checked by |
|---|---|---|---|---|
| within | `value` below `high`, or no `high` passed | read | the fill's length, the value text "8 of 10" in muted text | test |
| high | `value` at or past `high` | read | `data-high`; the fill and the value text in the bad colour, and the figure "9,420 of 10,000" that says how near the limit it is | test |
| over | `value` past `max` | read | the fill at the track's end and the real figure, "140 of 100" | test |
| unknown | `value` is not a finite number | read that the amount is not known | an empty fill and the words "Unknown of 10", MissingValue's word for a value nothing says, never "None of 10", which would read as none used | test |
| no range | `max` not above `min` | read | an empty fill, width 0 | test |

Example: Past its high mark the fill turns the bad colour, and the value says by how much (`docs/system/examples/meter/state-high.tsx`)

```tsx
import { Meter, MeterLabel, MeterValue } from "@/components/cobalt/ui/meter";

export default function Example() {
  return (
    <Meter className="w-full max-w-sm" value={9420} max={10000} high={9000}>
      <MeterLabel>Exports this month</MeterLabel>
      <MeterValue />
    </Meter>
  );
}
```

### State precedence
- High and over: both show. A value past `max` is also past `high`, so the fill covers the track in the bad colour and the text keeps the real figure.
- Unknown and high: unknown wins. A value that is not a number never counts as past `high`, so the fill stays empty and in the accent.
- No range and within: no range wins. The fill stays empty whatever the value.

### Motion
Not applicable: no motion

## Props

<!-- Props generated from registry/cobalt/ui/meter.tsx with TypeScript by scripts/props-table.mjs -->
### Meter

| Prop | Type | Default | Purpose |
|---|---|---|---|
| `value` | `number` |  |  |
| `format?` | `ValueFormat` | `"number"` | How the value and the limit read: "940 of 1,000". |
| `high?` | `number` |  | From here up the fill is in the bad colour: near or over the limit. |
| `locale?` | `string` |  |  |
| `none?` | `string` | `missingWords.unknown` | What a value that is not a number reads, before "of" and the limit: "Unknown of 10", never "None", which would say none is used. |

Also accepts every native `<div>` attribute; from Base UI: `aria-valuetext`, `getAriaValueText`, `max`, `min`, `render`.

### MeterLabel

No props of its own.

Also accepts every native `<span>` attribute; from Base UI: `render`.

### MeterValue

No props of its own.

Also accepts every native `<span>` attribute.

`value` is the amount used, `max` the limit (100 by default) and `min` the start (0 by default). `high` is the value from which the fill turns the bad colour; leave it out and the fill stays the accent. `format` shapes the value and the limit in the words, `none` is the word a value that is not a number reads, "Unknown" by default (`missingWords.unknown` from `registry/cobalt/lib/missing.ts`), and `locale` shapes the numbers. Base UI's other root props pass through, and `className` on the root sets the width. Children are `MeterLabel` and `MeterValue`, rendered before the track in a wrapping row.

## Usage

### When to use
- A fixed allowance that is used up and does not finish, such as seats on a plan, saved searches or exports this month.
- A level against a limit, where passing a mark is bad news and the amount still needs to be read.

### When not to use
- Work that finishes, such as an upload. Use Progress instead.
- An amount whose total is not known. Use Spinner instead.
- Names ranked by value, each read row by row. Use BarList instead.

### Rules
- `rule/meter-for-an-allowance-not-progress`: When the amount is a fixed allowance that is used up, render `Meter` instead of `Progress`, because a meter has `role="meter"` and reads "8 of 10", while a progress bar announces work that is on its way to finishing. Evidence: principle wcag: 4.1.2 Name, role, value; measured `role="meter"` with `aria-valuetext="8 of 10"`, registry/cobalt/ui/meter.test.tsx. Check: test `meter.test.tsx` expects `role="meter"` and `aria-valuetext="8 of 10"`.
  - Don't: `<Progress value={8} max={10}><ProgressLabel>Seats</ProgressLabel></Progress>`
  - Do: `<Meter value={8} max={10}><MeterLabel>Seats</MeterLabel><MeterValue /></Meter>`
- `rule/meter-set-high-below-max`: When a person should be warned before the allowance runs out, set `high` below `max`, such as 9,000 of 10,000, instead of leaving it out, because the fill turns the bad colour only from `high` up and stays the accent to the limit without it. Evidence: measured `bg-bad`, `text-bad` and `data-high` at 9,420 of 10,000 with `high` 9,000, registry/cobalt/ui/meter.test.tsx. Check: test `meter.test.tsx` expects `data-high`, `bg-bad` and `text-bad` past `high`.
  - Don't: `<Meter value={9420} max={10000}><MeterLabel>Exports this month</MeterLabel><MeterValue /></Meter>`
  - Do: `<Meter value={9420} max={10000} high={9000}><MeterLabel>Exports this month</MeterLabel><MeterValue /></Meter>`

### Content
- Follows `rule/writing-no-invented-numbers`.
- `rule/meter-label-names-the-allowance`: When a meter is placed, write `MeterLabel` as the noun of what is used, such as "Seats" or "Exports this month", instead of "Usage" or a sentence, because the label is the meter's accessible name and the amount is read after it as "8 of 10". Evidence: principle wcag: 4.1.2 Name, role, value; principle wcag: 2.4.6 Headings and Labels. Check: review of every `MeterLabel` in the examples and the showcase.
  - Don't: `<MeterLabel>Usage</MeterLabel>`
  - Do: `<MeterLabel>Exports this month</MeterLabel>`

### Anti-slop
- `rule/meter-fill-is-accent-until-high`: When a meter is under its `high` mark, leave the fill in the accent instead of colouring it good or by band, because a fill that says how much is used is what the accent's fill is for, and the bad colour past `high` is the one change the bar makes, which a second colour dilutes. Evidence: single use `registry/cobalt/ui/meter.tsx:62`, the fill is `bg-primary` under `high` and `bg-bad` from it, as Kaan asked on 2026-10-17 through audit B, where the fill stayed ink under every accent; principle wcag: 1.4.1 Use of color. Check: review of every `Meter` `className`; lint rule/ban-gradient (scripts/check-system.mjs) for a gradient fill.
  - Don't: `<Meter value={3} max={10} className="[&_[data-slot=meter-fill]]:bg-good" />`
  - Do: `<Meter value={3} max={10} high={9} />`

### Limits
Not applicable: a meter takes one value and one limit, a value past `max` or below `min` is held to the track, and `meter.test.tsx` renders 140 of 100, not a number and a limit of 0, so no count or length has a measured break.

## Accessibility
Rests on Base UI `Meter`, a `div` with `role="meter"`. The value text is `aria-hidden` and the same words are the meter's `aria-valuetext`, so the amount is read once, as "8 of 10". The fill and the bad colour are never the only cue: the figure is written beside the bar. Contrast of the fill, the value and the track: NEEDS REVIEW. Screen reader pass with VoiceOver: NEEDS REVIEW.

### Keyboard
| Key | Where focus is | Effect | Focus after | Checked by |
|---|---|---|---|---|
| Tab | before the meter | skips it, it is not focusable | the next control | by hand |

### ARIA
| Part | Role | Accessible name from | States and properties | Announced | Checked by |
|---|---|---|---|---|---|
| root | meter | `MeterLabel` through `aria-labelledby` | `aria-valuenow` held to the range, `aria-valuemin`, `aria-valuemax`, `aria-valuetext`; `data-high` | the name, "meter" and "8 of 10" when a reader reaches it; a change is not announced live | test |
| label | presentation | nothing | its `id`, which the root names | nothing of its own | by hand |
| value | none, `aria-hidden="true"` | nothing | none | nothing; the root's `aria-valuetext` carries the words | test |
| track and fill | none | nothing | none | nothing | by hand |

## Tokens
| Part | State | Token |
|---|---|---|
| track | all | `--muted` |
| fill | within | `--primary` |
| fill | high | `--bad` |
| label | all | `--foreground` |
| value | within | `--muted-foreground` |
| value | high | `--bad` |

## Related
- Progress: work that finishes, with a bar that fills toward its end.
- BarList: ranked names whose values are read row by row.
- Stat: one figure and its change, with no limit.
- Sparkline: a trend at a glance, with no axes, for a table cell or beside a figure.
- CompositionBar: the parts of one whole, side by side in one bar.
