← Components

Communication · Material 3: Progress indicators

Progress

How much of a task is done, as a bar or a ring. The fill overshoots and settles. With thresholds, a ring is a meter (context, storage).

Examples and variants

Bar

Determinate and indeterminate.

Uploading
x
x
Example
function ProgressBar() {
  const [value, setValue] = useState(40)
  return (
    <div className="flex w-full max-w-xs flex-col gap-4">
      <Progress value={value} label="Uploading" showValue />
      <Progress value={null} aria-label="Working" />
      <Button size="sm" variant="secondary" className="self-center" onClick={() => setValue((v) => (v >= 100 ? 0 : v + 20))}>
        +20
      </Button>
    </div>
  )
}

Ring and thresholds

Warning at 75, danger at 90.

60Contextx
x
Example
function ProgressRing() {
  const [value, setValue] = useState(60)
  return (
    <div className="flex items-center gap-6">
      <Progress shape="ring" value={value} thresholds={{ warning: 75, danger: 90 }} showValue label="Context" />
      <Progress shape="ring" value={null} size={28} aria-label="Working" />
      <Button size="sm" variant="secondary" onClick={() => setValue((v) => (v >= 100 ? 0 : v + 15))}>
        +15
      </Button>
    </div>
  )
}

Spec drawing

Measured from the live component at default density. Each code maps to the token that sets it; change the token and the drawing follows.

Install

With the CLI

The shadcn CLI only delivers files: it copies our code from the Isotopi registry into your project and installs the packages it uses. Add the foundation once, then the component.

Terminal
npx shadcn@latest add https://isotopi.com/r/minimal.json
npx shadcn@latest add https://isotopi.com/r/progress.json

By hand

No CLI needed. Add the foundation once (see Getting started), then follow these steps. They include every component this one builds on.

  1. Install the packages it uses.

    Terminal
    npm install @base-ui/react cn
  2. Copy this file to the same paths in your project. Imports use the @/ alias for your project root.

    • components/ui/progress.tsxprogress
      components/ui/progress.tsx
      "use client"
      
      import * as React from "react"
      import { Progress as ProgressPrimitive } from "@base-ui/react/progress"
      import { cn } from "cn"
      
      /*
        Progress: how much of a task is done (component-model.md §3 merges meters
        into it). shape="bar" or "ring". The fill moves with a small overshoot and
        its leading edge is rounded like liquid. `thresholds` turns the fill
        warning and danger past those values (context meters, character limits).
        value={null} is indeterminate: a short blob slides across.
      */
      type Thresholds = { warning?: number; danger?: number }
      
      function toneFor(value: number | null, thresholds?: Thresholds) {
        if (value === null || !thresholds) return "neutral"
        if (thresholds.danger !== undefined && value >= thresholds.danger) return "danger"
        if (thresholds.warning !== undefined && value >= thresholds.warning) return "warning"
        return "neutral"
      }
      
      function Progress({
        className,
        value,
        shape = "bar",
        thresholds,
        label,
        showValue = false,
        size = 40,
        ...props
      }: Omit<ProgressPrimitive.Root.Props, "value"> & {
        value: number | null
        shape?: "bar" | "ring"
        thresholds?: Thresholds
        label?: React.ReactNode
        showValue?: boolean
        /** Ring diameter in px. */
        size?: number
      }) {
        const tone = toneFor(value, thresholds)
        const complete = value !== null && value >= 100
      
        if (shape === "ring") {
          const stroke = 4 // matches --progress-ring-stroke
          const r = (size - stroke) / 2
          const c = 2 * Math.PI * r
          const pct = value === null ? 25 : Math.max(0, Math.min(100, value))
          return (
            <ProgressPrimitive.Root
              value={value}
              data-slot="progress"
              data-shape="ring"
              data-tone={tone}
              data-complete={complete || undefined}
              className={cn("progress inline-flex items-center gap-inline-sm", className)}
              {...props}
            >
              <span className="relative inline-flex" style={{ width: size, height: size }}>
                <svg aria-hidden width={size} height={size} viewBox={`0 0 ${size} ${size}`} className={cn("-rotate-90", value === null && "progress-ring-spin")}>
                  <circle cx={size / 2} cy={size / 2} r={r} fill="none" strokeWidth={stroke} className="stroke-(--progress-track)" />
                  <circle
                    cx={size / 2}
                    cy={size / 2}
                    r={r}
                    fill="none"
                    strokeWidth={stroke}
                    strokeLinecap="round"
                    strokeDasharray={c}
                    strokeDashoffset={c * (1 - pct / 100)}
                    className="progress-ring-fill"
                  />
                </svg>
                {showValue && value !== null ? (
                  <span className="absolute inset-0 flex items-center justify-center text-[0.625rem] font-medium tabular-nums">
                    {Math.round(value)}
                  </span>
                ) : null}
              </span>
              {label ? <ProgressPrimitive.Label className="text-sm">{label}</ProgressPrimitive.Label> : null}
            </ProgressPrimitive.Root>
          )
        }
      
        return (
          <ProgressPrimitive.Root
            value={value}
            data-slot="progress"
            data-shape="bar"
            data-tone={tone}
            data-complete={complete || undefined}
            className={cn("progress flex w-full flex-col gap-stack-xs", className)}
            {...props}
          >
            {label || showValue ? (
              <div className="flex items-center justify-between text-sm">
                {label ? <ProgressPrimitive.Label>{label}</ProgressPrimitive.Label> : <span />}
                {showValue ? <ProgressPrimitive.Value className="text-muted-foreground tabular-nums" /> : null}
              </div>
            ) : null}
            <ProgressPrimitive.Track className="relative h-(--progress-track-height) overflow-hidden rounded-(--progress-corner) bg-(--progress-track)">
              <ProgressPrimitive.Indicator className="progress-bar-fill h-full rounded-(--progress-corner)" />
            </ProgressPrimitive.Track>
          </ProgressPrimitive.Root>
        )
      }
      
      export { Progress }
      

Imports

What the examples on this page import:

Imports
import { Button } from "@/components/ui/button"
import { Progress } from "@/components/ui/progress"

Anatomy

  1. 1Track · --progress-track, --progress-track-height, --progress-corner.
  2. 2Fill · --progress-fill; --progress-fill-warning and -danger past thresholds.
  3. 3Label and value · Optional.

Props

PropTypeDefaultDescription
valuenumber | null—0 to 100; null is indeterminate.
shape"bar" | "ring""bar"Linear or circular.
thresholds{ warning?: number; danger?: number }—Colour changes past these values.
label, showValue, sizeReactNode, boolean, number—Label, percent text, ring diameter.

Tokens

Every visual spec is a component token in styles/tokens/components.css, pointing at a semantic token. Change a token to restyle the component; themes change the semantic layer.

TokenPoints toLightDark
--progress-track-heightvar(--space-2)8pxsame
--progress-trackvar(--surface-container-high)oklch(0.94 0.007 95)oklch(0.27 0 0)
--progress-fillvar(--color-fg-default)oklch(0.22 0.01 260)oklch(1 0 0)
--progress-fill-warningvar(--color-warning)oklch(0.72 0.14 75)oklch(0.78 0.15 75)
--progress-fill-dangervar(--color-danger)oklch(0.55 0.2 25)oklch(0.68 0.18 22)
--progress-cornervar(--shape-full)999pxsame
--progress-ring-strokevar(--space-1)4pxsame

Motion

TriggerWhat happensTokens
Value changeThe fill moves with a small overshoot.--duration-fill, --ease-bounce
CompleteA brief brighten, then settles.--duration-settle
IndeterminateA short blob slides across, stretching in the middle.--duration-sheen

Calm keeps the motion without overshoot. Still (and reduced motion) keeps a designed frame with no movement.

Accessibility

  • role=progressbar with aria-valuenow.
  • Label what's progressing.

Usage

Do

  • Use when you know how much is left.

Don’t

  • Don't use for unknown waits (use Loading indicator).

Code

components/ui/progress.tsx
"use client"

import * as React from "react"
import { Progress as ProgressPrimitive } from "@base-ui/react/progress"
import { cn } from "cn"

/*
  Progress: how much of a task is done (component-model.md §3 merges meters
  into it). shape="bar" or "ring". The fill moves with a small overshoot and
  its leading edge is rounded like liquid. `thresholds` turns the fill
  warning and danger past those values (context meters, character limits).
  value={null} is indeterminate: a short blob slides across.
*/
type Thresholds = { warning?: number; danger?: number }

function toneFor(value: number | null, thresholds?: Thresholds) {
  if (value === null || !thresholds) return "neutral"
  if (thresholds.danger !== undefined && value >= thresholds.danger) return "danger"
  if (thresholds.warning !== undefined && value >= thresholds.warning) return "warning"
  return "neutral"
}

function Progress({
  className,
  value,
  shape = "bar",
  thresholds,
  label,
  showValue = false,
  size = 40,
  ...props
}: Omit<ProgressPrimitive.Root.Props, "value"> & {
  value: number | null
  shape?: "bar" | "ring"
  thresholds?: Thresholds
  label?: React.ReactNode
  showValue?: boolean
  /** Ring diameter in px. */
  size?: number
}) {
  const tone = toneFor(value, thresholds)
  const complete = value !== null && value >= 100

  if (shape === "ring") {
    const stroke = 4 // matches --progress-ring-stroke
    const r = (size - stroke) / 2
    const c = 2 * Math.PI * r
    const pct = value === null ? 25 : Math.max(0, Math.min(100, value))
    return (
      <ProgressPrimitive.Root
        value={value}
        data-slot="progress"
        data-shape="ring"
        data-tone={tone}
        data-complete={complete || undefined}
        className={cn("progress inline-flex items-center gap-inline-sm", className)}
        {...props}
      >
        <span className="relative inline-flex" style={{ width: size, height: size }}>
          <svg aria-hidden width={size} height={size} viewBox={`0 0 ${size} ${size}`} className={cn("-rotate-90", value === null && "progress-ring-spin")}>
            <circle cx={size / 2} cy={size / 2} r={r} fill="none" strokeWidth={stroke} className="stroke-(--progress-track)" />
            <circle
              cx={size / 2}
              cy={size / 2}
              r={r}
              fill="none"
              strokeWidth={stroke}
              strokeLinecap="round"
              strokeDasharray={c}
              strokeDashoffset={c * (1 - pct / 100)}
              className="progress-ring-fill"
            />
          </svg>
          {showValue && value !== null ? (
            <span className="absolute inset-0 flex items-center justify-center text-[0.625rem] font-medium tabular-nums">
              {Math.round(value)}
            </span>
          ) : null}
        </span>
        {label ? <ProgressPrimitive.Label className="text-sm">{label}</ProgressPrimitive.Label> : null}
      </ProgressPrimitive.Root>
    )
  }

  return (
    <ProgressPrimitive.Root
      value={value}
      data-slot="progress"
      data-shape="bar"
      data-tone={tone}
      data-complete={complete || undefined}
      className={cn("progress flex w-full flex-col gap-stack-xs", className)}
      {...props}
    >
      {label || showValue ? (
        <div className="flex items-center justify-between text-sm">
          {label ? <ProgressPrimitive.Label>{label}</ProgressPrimitive.Label> : <span />}
          {showValue ? <ProgressPrimitive.Value className="text-muted-foreground tabular-nums" /> : null}
        </div>
      ) : null}
      <ProgressPrimitive.Track className="relative h-(--progress-track-height) overflow-hidden rounded-(--progress-corner) bg-(--progress-track)">
        <ProgressPrimitive.Indicator className="progress-bar-fill h-full rounded-(--progress-corner)" />
      </ProgressPrimitive.Track>
    </ProgressPrimitive.Root>
  )
}

export { Progress }