Meter
Displays a numeric value within a known range, such as disk usage or battery level.
Anatomy
<Meter.Root>
<Meter.Label />
<Meter.ValueText />
<Meter.Track>
<Meter.Indicator />
</Meter.Track>
</Meter.Root>
Meter or Progress?
A meter shows a reading within a range, like storage used or battery left. A progress bar tracks a task and finishes
with it. Use Progress for loading and uploads, and Meter for readings.
Examples
Basic
Pass a defaultValue between min and max (0 and 100 by default). It is formatted as a percentage.
Value State
low, high and optimum split the range into regions, like the HTML <meter> element. The root, track and indicator
expose the result as data-state: optimal, suboptimal or least-optimal.
Put optimum below low when lower is better (server load) and above high when higher is better (battery). Regions
are exclusive at the optimal end, so with high={80} a value of 80 is still suboptimal.
Format Options
formatOptions is passed to Intl.NumberFormat. Any style other than percent formats the raw value, which suits
currency and units.
Value Text
The value translation describes the value in words. It sets both ValueText and the announced aria-valuetext.
Min and Max
Set min and max for ranges that don't start at zero.
Vertical
Set orientation="vertical" to fill from the bottom. The indicator's height is set instead of its width.
Battery
Without a visible label, pass an aria-label. Set optimum above high so a full battery is optimal and a nearly
empty one is least optimal.
Password Strength
Map each strength score to a word with the value translation. Let data-state color the bar.
Context
Use Context to read valueState and render content that depends on it.
Root Provider
Use the useMeter hook with RootProvider to read and update the value from outside the component.
Guides
Styling
The indicator's width (or height when vertical) is set inline, so the track only needs a size and
overflow: hidden. The root exposes the fill as --percent.
[data-meter-indicator][data-state='optimal'] {
background: green;
}
[data-meter-indicator][data-state='suboptimal'] {
background: orange;
}
[data-meter-indicator][data-state='least-optimal'] {
background: red;
}
Accessibility
The root has role="meter" with aria-valuenow, aria-valuemin, aria-valuemax and aria-valuetext set from the
formatted value. Label names the meter. Without one, pass an aria-label to the root. ValueText is hidden from
assistive technology because aria-valuetext already announces the value.
API Reference
Props
Root
Defines the <div> element.
| Attribute | Default | Type |
|---|---|---|
asChild | booleanUse the provided child element as the default rendered element, combining their props and behavior. Use `render` when you need the part's state: `render={(props, state) => <MyButton {...props} />}`. For more details, read our Composition guide. | |
defaultValue | min | numberThe initial value of the meter when rendered. Use when you don't need to control the value of the meter. |
formatOptions | { style: 'percent' } | NumberFormatOptionsThe options to use for formatting the value. |
high | numberThe lower numeric bound of the high end of the measured range. Defaults to `max`. | |
id | stringThe unique identifier of the machine. | |
ids | Partial<{ label: string }>The ids of the elements in the meter. Useful when the label lives outside the machine and you need to control `aria-labelledby`. | |
locale | stringThe locale to use for formatting the value. | |
low | numberThe upper numeric bound of the low end of the measured range. Defaults to `min`. | |
max | 100 | numberThe maximum allowed value of the meter. |
min | 0 | numberThe minimum allowed value of the meter. |
onValueChange | (details: ValueChangeDetails) => voidCallback fired when the value changes. | |
optimum | numberThe optimal numeric value. Combined with `low` and `high`, this decides which region is preferred (HTML `<meter>` algorithm). Defaults to the midpoint of `min` and `max`. | |
orientation | 'horizontal' | 'horizontal' | 'vertical'The orientation of the element. |
render | ReactElement<unknown, string | JSXElementConstructor<any>> | RenderFn<EmptyState>Render the part as a custom element, combining their props and behavior. Pass an element to have the part's props merged into it, or a function to control the merge yourself and read the part's state. | |
translations | IntlTranslationsThe localized messages to use. | |
value | numberThe controlled value of the meter. |
| Attribute | Description |
|---|---|
[data-meter-root] | <uid> |
[data-value] | The value of the item |
[data-state] | "optimal" | "suboptimal" | "least-optimal" |
[data-orientation] | The orientation of the meter |
| CSS Variable | Description |
|---|---|
--percent | The percent value for the Root |
Indicator
Defines the <div> element.
| Attribute | Default | Type |
|---|---|---|
asChild | booleanUse the provided child element as the default rendered element, combining their props and behavior. Use `render` when you need the part's state: `render={(props, state) => <MyButton {...props} />}`. For more details, read our Composition guide. | |
render | ReactElement<unknown, string | JSXElementConstructor<any>> | RenderFn<EmptyState>Render the part as a custom element, combining their props and behavior. Pass an element to have the part's props merged into it, or a function to control the merge yourself and read the part's state. |
| Attribute | Description |
|---|---|
[data-meter-indicator] | <uid> |
[data-orientation] | The orientation of the indicator |
[data-state] | "optimal" | "suboptimal" | "least-optimal" |
Label
Defines the <span> element.
| Attribute | Default | Type |
|---|---|---|
asChild | booleanUse the provided child element as the default rendered element, combining their props and behavior. Use `render` when you need the part's state: `render={(props, state) => <MyButton {...props} />}`. For more details, read our Composition guide. | |
render | ReactElement<unknown, string | JSXElementConstructor<any>> | RenderFn<EmptyState>Render the part as a custom element, combining their props and behavior. Pass an element to have the part's props merged into it, or a function to control the merge yourself and read the part's state. |
| Attribute | Description |
|---|---|
[data-meter-label] | <uid> |
[data-orientation] | The orientation of the label |
RootProvider
Defines the <div> element.
| Attribute | Default | Type |
|---|---|---|
value | UseMeterReturn | |
asChild | booleanUse the provided child element as the default rendered element, combining their props and behavior. Use `render` when you need the part's state: `render={(props, state) => <MyButton {...props} />}`. For more details, read our Composition guide. | |
render | ReactElement<unknown, string | JSXElementConstructor<any>> | RenderFn<EmptyState>Render the part as a custom element, combining their props and behavior. Pass an element to have the part's props merged into it, or a function to control the merge yourself and read the part's state. |
Track
Defines the <div> element.
| Attribute | Default | Type |
|---|---|---|
asChild | booleanUse the provided child element as the default rendered element, combining their props and behavior. Use `render` when you need the part's state: `render={(props, state) => <MyButton {...props} />}`. For more details, read our Composition guide. | |
render | ReactElement<unknown, string | JSXElementConstructor<any>> | RenderFn<EmptyState>Render the part as a custom element, combining their props and behavior. Pass an element to have the part's props merged into it, or a function to control the merge yourself and read the part's state. |
| Attribute | Description |
|---|---|
[data-meter-track] | <uid> |
[data-orientation] | The orientation of the track |
[data-state] | "optimal" | "suboptimal" | "least-optimal" |
ValueText
Defines the <span> element.
| Attribute | Default | Type |
|---|---|---|
asChild | booleanUse the provided child element as the default rendered element, combining their props and behavior. Use `render` when you need the part's state: `render={(props, state) => <MyButton {...props} />}`. For more details, read our Composition guide. | |
render | ReactElement<unknown, string | JSXElementConstructor<any>> | RenderFn<EmptyState>Render the part as a custom element, combining their props and behavior. Pass an element to have the part's props merged into it, or a function to control the merge yourself and read the part's state. |