---
title: "Meter · Ark UI — StyleX Blocks"
description: "Static gauges for a value within a known range, like storage or quota, with the progress bar look."
url: "https://stylexblocks.com/components/ark-ui/meter/"
agent:
  instructions: "Use this search API to find relevant components and blocks across this site with keywords or natural-language queries, instead of crawling individual pages. Results are returned in Markdown."
  endpoint: "https://stylexblocks.com/.well-known/search?q={query}"
  method: "GET"
  documentation: "https://developers.cloudflare.com/ai-search/how-to/search-for-agents/"
---

# Meter

Static gauges for a value within a known range, like storage or quota, with the progress bar look.

- Behavior engine: Ark UI
- Also available for: [Base UI](https://stylexblocks.com/components/base-ui/meter.md), [UI SDK](https://stylexblocks.com/components/ui-sdk/meter.md)
- Category: Feedback
- Variants: outline, subtle
- Sizes: xs, sm, md, lg, xl
- HTML page: https://stylexblocks.com/components/ark-ui/meter/

## Install

Configure the project once (sets the behavior engine and import aliases):

```sh
npx stylexblocks init
```

Then add the item as source you own:

```sh
npx stylexblocks add meter
```

Equivalent: `npx shadcn add @stylexblocks/meter`. Registry item JSON: https://stylexblocks.com/r/ark-ui/meter.json

## Usage

```tsx
import { Meter } from "#components/ui/ark-ui/meter.tsx";
import { indigoPalette } from "@stylexblocks/ui/themes/palettes.ts";

export function Example() {
  return (
    // a hand-built role="meter" on Ark's factory (Ark ships no meter
    // machine) wearing the progress recipe; variant/size/shape resolve once
    // on Root and Track/Range inherit them via context
    <Meter.Root value={64} variant="outline" size="md" shape="full" palette={indigoPalette}>
      <Meter.Label>Storage</Meter.Label>
      <Meter.ValueText />
      <Meter.Track>
        <Meter.Range />
      </Meter.Track>
    </Meter.Root>
  );
}

// units: <Meter.Root value={3.2} max={8} formatOptions={{ style: "unit", unit: "gigabyte" }}>
```

## Examples

### Custom range and format

Set min/max for real units and format the value text; it also becomes the root's aria-valuetext.

```tsx
import { Meter } from "#components/ui/ark-ui/meter.tsx";

export function Example() {
  return (
    <Meter.Root
      value={3.2}
      max={8}
      formatOptions={{ style: "unit", unit: "gigabyte", maximumFractionDigits: 1 }}
    >
      <Meter.Label>Storage</Meter.Label>
      <Meter.ValueText />
      <Meter.Track>
        <Meter.Range />
      </Meter.Track>
    </Meter.Root>
  );
}
```

### Thresholds

Pick the palette from the value to flag levels: healthy, getting full, critical.

```tsx
import { Meter } from "#components/ui/ark-ui/meter.tsx";
import { amberPalette, greenPalette, redPalette } from "@stylexblocks/ui/themes/palettes.ts";

const paletteFor = (v: number) => (v >= 90 ? redPalette : v >= 70 ? amberPalette : greenPalette);

export function Example({ value }: { value: number }) {
  return (
    <Meter.Root value={value} variant="subtle" shape="full" palette={paletteFor(value)}>
      <Meter.Label>API quota</Meter.Label>
      <Meter.ValueText />
      <Meter.Track>
        <Meter.Range />
      </Meter.Track>
    </Meter.Root>
  );
}
```

## Source

`components/ui/ark-ui/meter.tsx`

```tsx
import { createContext, useContext, useEffect, useId, useMemo, useState } from "react";
import { ark, type HTMLArkProps } from "@ark-ui/react/factory";
import { useLocaleContext } from "@ark-ui/react/locale";
import { createSlotRecipeContext } from "#lib/ark-ui/create-slot-recipe-context.tsx";
import {
  defineSlotRecipe,
  type SlotRecipeVariants,
  type WithStyleOverrides,
} from "#lib/recipe-props.ts";
import * as stylex from "@stylexjs/stylex";
import { colorPalette } from '@stylexblocks/ui/color-palette.stylex.ts'
import { durations } from '@stylexblocks/ui/tokens/durations.stylex.ts'
import { fontSizes } from '@stylexblocks/ui/tokens/font-sizes.stylex.ts'
import { fontWeights } from '@stylexblocks/ui/tokens/font-weights.stylex.ts'
import { lineHeights } from '@stylexblocks/ui/tokens/line-heights.stylex.ts'
import { radii } from '@stylexblocks/ui/tokens/radii.stylex.ts'
import { semanticColors } from '@stylexblocks/ui/semantic-tokens/colors.stylex.ts'
import { semanticRadii } from '@stylexblocks/ui/semantic-tokens/radii.stylex.ts'
import { semanticShadows } from '@stylexblocks/ui/semantic-tokens/shadows.stylex.ts'
import { sizes } from '@stylexblocks/ui/tokens/sizes.stylex.ts'

const progressRoot = stylex.create({
  base: {
    fontSize: fontSizes.sm,
    lineHeight: lineHeights.sm,
    position: 'relative',
  },
})

const progressTrack = stylex.create({
  base: {
    overflow: 'hidden',
    position: 'relative',
  },
})

const progressTrackSizes = stylex.create({
  xs: {
    height: sizes._1_5,
  },
  sm: {
    height: sizes._2,
  },
  md: {
    height: sizes._2_5,
  },
  lg: {
    height: sizes._3,
  },
  xl: {
    height: sizes._4,
  },
})

const progressTrackVariants = stylex.create({
  outline: {
    boxShadow: semanticShadows.inset,
    backgroundColor: semanticColors.bgSubtle,
  },
  subtle: {
    backgroundColor: colorPalette.muted,
  },
})

const progressTrackShapes = stylex.create({
  rounded: {
    borderRadius: semanticRadii.control,
  },
  full: {
    borderRadius: radii.full,
  },
})

const progressRange = stylex.create({
  base: {
    display: 'flex',
    alignItems: 'center',
    justifyContent: 'center',
    transitionProperty: 'width, height',
    transitionDuration: durations.slow,
    height: '100%',
    backgroundColor: 'var(--track-color)',
  },
})

const progressRangeVariants = stylex.create({
  outline: {
    backgroundColor: colorPalette.solid,
  },
  subtle: {
    backgroundColor: `color-mix(in oklch, ${colorPalette.solid} 72%, transparent)`,
  },
})

const progressRangeStripeds = stylex.create({
  true: {
    backgroundImage:
      'linear-gradient(45deg, var(--stripe-color) 25%, transparent 25%, transparent 50%, var(--stripe-color) 50%, var(--stripe-color) 75%, transparent 75%, transparent)',
    backgroundSize: 'var(--stripe-size) var(--stripe-size)',
    '--stripe-size': '1rem',
    '--stripe-color': 'rgba(255, 255, 255, 0.3)',
  },
})

const progressRangeAnimateds = stylex.create({
  true: {
    '--animate-from': 'var(--stripe-size)',
    animationName: 'bg-position',
    animationDuration: '1s',
    animationTimingFunction: 'linear',
    animationIterationCount: 'infinite',
  },
})

const progressLabel = stylex.create({
  base: {
    display: 'inline-flex',
    fontWeight: fontWeights.medium,
  },
})

const progressValueText = stylex.create({
  base: {
    fontSize: fontSizes.xs,
    lineHeight: 1,
    fontWeight: fontWeights.medium,
  },
})

export type ProgressVariant = keyof typeof progressTrackVariants

export type ProgressShape = keyof typeof progressTrackShapes

export type ProgressStriped = keyof typeof progressRangeStripeds

export type ProgressAnimated = keyof typeof progressRangeAnimateds

export type ProgressSize = keyof typeof progressTrackSizes

// A meter is a static gauge (disk usage, quota, strength), not a task in
// flight, but it looks like a progress bar: reuse the progress recipe.
const meterSlotRecipe = defineSlotRecipe({
  slots: {
    root: { styles: progressRoot },
    track: {
      styles: progressTrack,
      sizes: progressTrackSizes,
      variants: progressTrackVariants,
      shapes: progressTrackShapes,
    },
    range: {
      styles: progressRange,
      variants: progressRangeVariants,
    },
    label: { styles: progressLabel },
    valueText: { styles: progressValueText },
  },
  defaultVariants: { variant: "outline", size: "md", shape: "rounded" },
});

const { withProvider, withContext } = createSlotRecipeContext(meterSlotRecipe);

type MeterVariants = SlotRecipeVariants<typeof meterSlotRecipe>;

// Ark UI has no meter machine; the component derives the gauge state from
// its props and hands it to the parts through context.
interface MeterState {
  value: number;
  percent: number;
  valueText: string;
  setLabelId: (id: string | undefined) => void;
}

const MeterContext = createContext<MeterState>({
  value: 0,
  percent: 0,
  valueText: "",
  setLabelId: () => {},
});

const clamp = (n: number, lo: number, hi: number) => Math.min(Math.max(n, lo), hi);

interface MeterOwnProps {
  /** The current value. */
  value: number;
  /** @default 0 */
  min?: number;
  /** @default 100 */
  max?: number;
  /**
   * Formats the value for ValueText and `aria-valuetext`. Without it the
   * value renders as a percentage of the range.
   */
  formatOptions?: Intl.NumberFormatOptions;
  /** Locale for the formatter; defaults to Ark's LocaleProvider. */
  locale?: string;
}

function RootNode({
  value,
  min = 0,
  max = 100,
  formatOptions,
  locale,
  children,
  ...rest
}: HTMLArkProps<"div"> & MeterOwnProps) {
  const { locale: contextLocale } = useLocaleContext();
  const [labelId, setLabelId] = useState<string | undefined>();
  const clamped = clamp(Number.isNaN(value) ? min : value, min, max);
  const percent = max === min ? 0 : ((clamped - min) / (max - min)) * 100;
  const valueText = formatOptions
    ? new Intl.NumberFormat(locale ?? contextLocale, formatOptions).format(clamped)
    : new Intl.NumberFormat(locale ?? contextLocale, { style: "percent" }).format(
        percent / 100,
      );
  const state = useMemo<MeterState>(
    () => ({ value: clamped, percent, valueText, setLabelId }),
    [clamped, percent, valueText],
  );
  return (
    <MeterContext.Provider value={state}>
      <ark.div
        role="meter"
        aria-valuemin={min}
        aria-valuemax={max}
        aria-valuenow={clamped}
        aria-valuetext={valueText}
        aria-labelledby={labelId}
        {...rest}
      >
        {children}
      </ark.div>
    </MeterContext.Provider>
  );
}

function LabelNode({ id, ...rest }: HTMLArkProps<"span">) {
  const { setLabelId } = useContext(MeterContext);
  const generated = useId();
  const labelId = id ?? generated;
  useEffect(() => {
    setLabelId(labelId);
    return () => setLabelId(undefined);
  }, [labelId, setLabelId]);
  return <ark.span id={labelId} {...rest} />;
}

function RangeNode({ style, ...rest }: HTMLArkProps<"div">) {
  const { percent } = useContext(MeterContext);
  return <ark.div {...rest} style={{ ...style, width: `${percent}%` }} />;
}

function ValueTextNode({ children, ...rest }: HTMLArkProps<"span">) {
  const { valueText } = useContext(MeterContext);
  // the root already announces aria-valuetext; the visible copy is decorative
  return (
    <ark.span aria-hidden {...rest}>
      {children ?? valueText}
    </ark.span>
  );
}

/**
 * Meter — a hand-built `role="meter"` gauge on Ark's `ark` factory wearing
 * the progress recipe (Ark UI ships no meter machine). Root carries
 * `aria-valuenow/min/max/text` and is labelled by Label; `variant`, `size`
 * and `shape` resolve once on Root and Track/Range inherit them via
 * context. `formatOptions` / `locale` drive the ValueText (a percentage by
 * default). Every part composes via `asChild`.
 */
export type MeterRootProps = WithStyleOverrides<HTMLArkProps<"div"> & MeterOwnProps> &
  Partial<MeterVariants>;

const MeterRoot = withProvider(RootNode, "root", "MeterRoot");

function Root(props: MeterRootProps) {
  return <MeterRoot {...(props as React.ComponentProps<typeof MeterRoot>)} />;
}
Root.displayName = "MeterRoot";

export const Meter = {
  Root,
  Label: withContext(LabelNode, "label", "MeterLabel"),
  Track: withContext("div", "track", "MeterTrack"),
  Range: withContext(RangeNode, "range", "MeterRange"),
  ValueText: withContext(ValueTextNode, "valueText", "MeterValueText"),
};
```
