Skip to content

ComponentsFeedback

SourceSource

Progress Bar

A gradient progress bar for boosts, uploads and other long-running tasks.

A bar that fills from the start edge as a task advances. Use it for uploads, server boosts and other work that has a known end.

It is built on Radix Progress in React and Reka UI Progress in Vue. The primitive sets the role and the value attributes. ProgressLabel is a plain row for the text above the bar.

Root class newt-progress
import { Progress, ProgressLabel } from "@/registry/bases/newt/ui/progress"

export default function ProgressDemo() {
  return (
    <div className="w-full max-w-sm">
      <ProgressLabel>
        <span>Label</span>
        <span>50%</span>
      </ProgressLabel>
      <Progress value={50} />
    </div>
  )
}
<script setup lang="ts">
import { Progress, ProgressLabel } from "~~/registry/bases/newt/ui/progress"
</script>

<template>
  <div class="w-full max-w-sm">
    <ProgressLabel>
      <span>Label</span>
      <span>50%</span>
    </ProgressLabel>
    <Progress :value="50" />
  </div>
</template>

Installation

npx newtui@latest add progressnpx shadcn@latest add @newtui/progressnpx shadcn-vue@latest add @newtui/progresspnpm dlx newtui@latest add progresspnpm dlx shadcn@latest add @newtui/progresspnpm dlx shadcn-vue@latest add @newtui/progressyarn dlx newtui@latest add progressyarn dlx shadcn@latest add @newtui/progressyarn dlx shadcn-vue@latest add @newtui/progressbunx newtui@latest add progressbunx shadcn@latest add @newtui/progressbunx shadcn-vue@latest add @newtui/progressdeno run -A npm:newtui@latest add progressdeno run -A npm:shadcn@latest add @newtui/progressdeno run -A npm:shadcn-vue@latest add @newtui/progressvlx newtui@latest add progressvlx shadcn@latest add @newtui/progressvlx shadcn-vue@latest add @newtui/progressvp dlx newtui@latest add progressvp dlx shadcn@latest add @newtui/progressvp dlx shadcn-vue@latest add @newtui/progressnubx newtui@latest add progressnubx shadcn@latest add @newtui/progressnubx shadcn-vue@latest add @newtui/progressnlx newtui@latest add progressnlx shadcn@latest add @newtui/progressnlx shadcn-vue@latest add @newtui/progressupx newtui@latest add progressupx shadcn@latest add @newtui/progressupx shadcn-vue@latest add @newtui/progress

The shadcn CLI needs the @newtui registry in your components.json. Set it up.

Install the dependencies

npm install class-variance-authority radix-uipnpm add class-variance-authority radix-uiyarn add class-variance-authority radix-uibun add class-variance-authority radix-uideno add npm:class-variance-authority npm:radix-uivlt install class-variance-authority radix-uivp add class-variance-authority radix-uinub add class-variance-authority radix-uini class-variance-authority radix-uiupm add class-variance-authority radix-ui
npm install class-variance-authority reka-uipnpm add class-variance-authority reka-uiyarn add class-variance-authority reka-uibun add class-variance-authority reka-uideno add npm:class-variance-authority npm:reka-uivlt install class-variance-authority reka-uivp add class-variance-authority reka-uinub add class-variance-authority reka-uini class-variance-authority reka-uiupm add class-variance-authority reka-ui

Copy the source into your project

"use client"

import { cva, type VariantProps } from "class-variance-authority"
import { Progress as ProgressPrimitive } from "radix-ui"
import * as React from "react"

import { cn } from "@/lib/utils"

const progressVariants = cva(
  "h-full rounded-full transition-[width] duration-base ease-newt",
  {
    variants: {
      variant: {
        default: "bg-[linear-gradient(90deg,var(--newt-brand),#8c54ff)]",
        success: "bg-[linear-gradient(90deg,var(--newt-online),#45c178)]",
        danger: "bg-[linear-gradient(90deg,var(--newt-dnd),#f4878a)]",
      },
    },
    defaultVariants: {
      variant: "default",
    },
  }
)

export interface ProgressProps
  extends
    Omit<
      React.ComponentPropsWithoutRef<typeof ProgressPrimitive.Root>,
      "value"
    >,
    VariantProps<typeof progressVariants> {
  /** Current value, 0–max */
  value?: number
  indicatorClassName?: string
}

/*
 * Radix owns the semantics: `role="progressbar"`, the `aria-value*`
 * attributes and `data-state` (`loading` or `complete`). Only the look is
 * newt/ui's.
 */
const Progress = React.forwardRef<
  React.ComponentRef<typeof ProgressPrimitive.Root>,
  ProgressProps
>(
  (
    { className, indicatorClassName, value = 0, max = 100, variant, ...props },
    ref
  ) => {
    /* Radix reads a value outside 0–max as indeterminate, so clamp it first. */
    const limit = max > 0 ? max : 100
    const clamped = Math.min(Math.max(value, 0), limit)
    return (
      <ProgressPrimitive.Root
        ref={ref}
        value={clamped}
        max={limit}
        className={cn(
          "h-2 w-full overflow-hidden rounded-full bg-newt-bg-base",
          className
        )}
        {...props}
      >
        <ProgressPrimitive.Indicator
          className={cn(progressVariants({ variant }), indicatorClassName)}
          style={{ width: `${(clamped / limit) * 100}%` }}
        />
      </ProgressPrimitive.Root>
    )
  }
)
Progress.displayName = "Progress"

const ProgressLabel = React.forwardRef<
  HTMLDivElement,
  React.HTMLAttributes<HTMLDivElement>
>(({ className, ...props }, ref) => (
  <div
    ref={ref}
    className={cn(
      "mb-1.5 flex justify-between text-xs text-newt-text-muted",
      className
    )}
    {...props}
  />
))
ProgressLabel.displayName = "ProgressLabel"

export { Progress, ProgressLabel, progressVariants }
<script setup lang="ts">
import {
  ProgressIndicator,
  ProgressRoot,
  type ProgressRootProps,
} from "reka-ui"
import { computed, type HTMLAttributes } from "vue"

import { cn } from "@/lib/utils"

import { type ProgressVariants, progressVariants } from "."

/*
 * Reka owns the semantics: `role="progressbar"`, the `aria-value*`
 * attributes and `data-state` (`loading` or `complete`). Only the look is
 * newt/ui's.
 */
const props = withDefaults(
  defineProps<
    Pick<ProgressRootProps, "as" | "asChild"> & {
      /** Current value, 0–max */
      value?: number
      max?: number
      /** Builds `aria-valuetext`. The default is the rounded percentage. */
      getValueLabel?: (value: number, max: number) => string
      variant?: ProgressVariants["variant"]
      indicatorClass?: HTMLAttributes["class"]
      class?: HTMLAttributes["class"]
    }
  >(),
  {
    value: 0,
    max: 100,
    getValueLabel: (value: number, max: number) =>
      `${Math.round((value / max) * 100)}%`,
  }
)

/* Reka reads a value outside 0–max as indeterminate, so clamp it first. */
const limit = computed(() => (props.max > 0 ? props.max : 100))
const clamped = computed(() => Math.min(Math.max(props.value, 0), limit.value))

/*
 * Reka names the bar after its percentage by default. The value belongs in
 * `aria-valuetext`, as Radix has it, so the name stays the caller's.
 */
function valueText(value: number | null | undefined, max: number) {
  if (value === null || value === undefined) return undefined
  return props.getValueLabel(value, max)
}
function noLabel() {
  return undefined
}
</script>

<template>
  <ProgressRoot
    :as="props.as"
    :as-child="props.asChild"
    :model-value="clamped"
    :max="limit"
    :get-value-text="valueText"
    :get-value-label="noLabel"
    :class="
      cn('h-2 w-full overflow-hidden rounded-full bg-newt-bg-base', props.class)
    "
  >
    <ProgressIndicator
      :class="
        cn(progressVariants({ variant: props.variant }), props.indicatorClass)
      "
      :style="{ width: `${(clamped / limit) * 100}%` }"
    />
  </ProgressRoot>
</template>
<script setup lang="ts">
import type { HTMLAttributes } from "vue"

import { cn } from "@/lib/utils"

const props = defineProps<{ class?: HTMLAttributes["class"] }>()
</script>

<template>
  <div
    :class="
      cn(
        'mb-1.5 flex justify-between text-xs text-newt-text-muted',
        props.class
      )
    "
  >
    <slot />
  </div>
</template>
import { cva, type VariantProps } from "class-variance-authority"

export { default as Progress } from "./Progress.vue"
export { default as ProgressLabel } from "./ProgressLabel.vue"

export const progressVariants = cva(
  "h-full rounded-full transition-[width] duration-base ease-newt",
  {
    variants: {
      variant: {
        default: "bg-[linear-gradient(90deg,var(--newt-brand),#8c54ff)]",
        success: "bg-[linear-gradient(90deg,var(--newt-online),#45c178)]",
        danger: "bg-[linear-gradient(90deg,var(--newt-dnd),#f4878a)]",
      },
    },
    defaultVariants: {
      variant: "default",
    },
  }
)

export type ProgressVariants = VariantProps<typeof progressVariants>

Update the import paths

The files import @/lib/utils and sibling components through the aliases in your components.json. Point them at wherever those live in your project.

No CLI, no components.json: paste this into Claude, Cursor, Copilot or any coding assistant and it adds Progress Bar to your React project by hand. The prompt carries the source of every file the CLI would write — this component's and those of the components it builds on — with the imports already pointed at the default aliases.

No CLI, no components.json: paste this into Claude, Cursor, Copilot or any coding assistant and it adds Progress Bar to your Vue project by hand. The prompt carries the source of every file the CLI would write — this component's and those of the components it builds on — with the imports already pointed at the default aliases.

Usage

import { Progress } from "@/components/ui/progress"

export function Example() {
  return <Progress />
}
<script setup lang="ts">
import { Progress, ProgressLabel } from "@/components/ui/progress"
</script>

<template>
  <Progress />
</template>

Examples

Variants

success for something that finished and danger for a limit about to be reached; the default gradient is for work still going on. The visible label sits outside the bar, so each bar repeats it as its aria-label.

Root class newt-progress
import { Progress, ProgressLabel } from "@/registry/bases/newt/ui/progress"

/* The label is outside the bar, so each bar repeats it as its `aria-label`. */
export default function ProgressVariantsDemo() {
  return (
    <div className="flex w-full max-w-sm flex-col gap-4">
      <div>
        <ProgressLabel>
          <span>Uploading clip</span>
          <span>60%</span>
        </ProgressLabel>
        <Progress value={60} aria-label="Uploading clip" />
      </div>
      <div>
        <ProgressLabel>
          <span>Backup finished</span>
          <span>100%</span>
        </ProgressLabel>
        <Progress variant="success" value={100} aria-label="Backup finished" />
      </div>
      <div>
        <ProgressLabel>
          <span>Storage almost full</span>
          <span>92%</span>
        </ProgressLabel>
        <Progress
          variant="danger"
          value={92}
          aria-label="Storage almost full"
        />
      </div>
    </div>
  )
}
<script setup lang="ts">
import { Progress, ProgressLabel } from "~~/registry/bases/newt/ui/progress"
</script>

<template>
  <!-- The label is outside the bar, so each bar repeats it as its `aria-label`. -->
  <div class="flex w-full max-w-sm flex-col gap-4">
    <div>
      <ProgressLabel>
        <span>Uploading clip</span>
        <span>60%</span>
      </ProgressLabel>
      <Progress :value="60" aria-label="Uploading clip" />
    </div>
    <div>
      <ProgressLabel>
        <span>Backup finished</span>
        <span>100%</span>
      </ProgressLabel>
      <Progress variant="success" :value="100" aria-label="Backup finished" />
    </div>
    <div>
      <ProgressLabel>
        <span>Storage almost full</span>
        <span>92%</span>
      </ProgressLabel>
      <Progress variant="danger" :value="92" aria-label="Storage almost full" />
    </div>
  </div>
</template>

A custom maximum

Set max to count in the thing’s own unit, such as 3 boosts of 7, instead of working out a percentage by hand.

Root class newt-progress
"use client"

import { Progress, ProgressLabel } from "@/registry/bases/newt/ui/progress"

/*
 * `max` keeps the count in its own unit: no percentage to work out by hand.
 * `getValueLabel` makes a screen reader say "3 of 7" too, not "43%".
 */
export default function ProgressMaxDemo() {
  return (
    <div className="w-full max-w-sm">
      <ProgressLabel>
        <span>Server boosts</span>
        <span>3 of 7</span>
      </ProgressLabel>
      <Progress
        value={3}
        max={7}
        getValueLabel={(value, max) => `${value} of ${max}`}
        aria-label="Server boosts"
      />
    </div>
  )
}
<script setup lang="ts">
import { Progress, ProgressLabel } from "~~/registry/bases/newt/ui/progress"
</script>

<template>
  <!-- `max` keeps the count in its own unit: no percentage to work out by hand. -->
  <div class="w-full max-w-sm">
    <ProgressLabel>
      <span>Server boosts</span>
      <span>3 of 7</span>
    </ProgressLabel>
    <Progress
      :value="3"
      :max="7"
      :get-value-label="(value: number, max: number) => `${value} of ${max}`"
      aria-label="Server boosts"
    />
  </div>
</template>

Controlled

The bar holds no state: it draws the value it is given and eases to the next one. Here the variant changes to success when the value reaches the end.

Root class newt-progress
"use client"

import * as React from "react"

import { Button } from "@/registry/bases/newt/ui/button"
import { Progress, ProgressLabel } from "@/registry/bases/newt/ui/progress"

/*
 * The bar holds no state: it draws the `value` it is given and eases between
 * two of them. Reaching the end is a change of variant, not only of width.
 */
export default function ProgressControlledDemo() {
  const [value, setValue] = React.useState(40)
  const done = value >= 100

  return (
    <div className="flex w-full max-w-sm flex-col gap-3">
      <div>
        <ProgressLabel>
          <span>{done ? "Upload complete" : "Uploading clip"}</span>
          <span>{value}%</span>
        </ProgressLabel>
        <Progress
          value={value}
          variant={done ? "success" : "default"}
          aria-label="Upload"
        />
      </div>
      <div className="flex flex-wrap gap-2">
        <Button
          size="sm"
          disabled={done}
          onClick={() => setValue((current) => Math.min(current + 20, 100))}
        >
          Add 20%
        </Button>
        <Button size="sm" variant="secondary" onClick={() => setValue(0)}>
          Start over
        </Button>
      </div>
    </div>
  )
}
<script setup lang="ts">
import { computed, ref } from "vue"
import { Button } from "~~/registry/bases/newt/ui/button"
import { Progress, ProgressLabel } from "~~/registry/bases/newt/ui/progress"

/*
 * The bar holds no state: it draws the `value` it is given and eases between
 * two of them. Reaching the end is a change of variant, not only of width.
 */
const value = ref(40)
const done = computed(() => value.value >= 100)
</script>

<template>
  <div class="flex w-full max-w-sm flex-col gap-3">
    <div>
      <ProgressLabel>
        <span>{{ done ? "Upload complete" : "Uploading clip" }}</span>
        <span>{{ value }}%</span>
      </ProgressLabel>
      <Progress
        :value="value"
        :variant="done ? 'success' : 'default'"
        aria-label="Upload"
      />
    </div>
    <div class="flex flex-wrap gap-2">
      <Button
        size="sm"
        :disabled="done"
        @click="value = Math.min(value + 20, 100)"
      >
        Add 20%
      </Button>
      <Button size="sm" variant="secondary" @click="value = 0">
        Start over
      </Button>
    </div>
  </div>
</template>

API reference

Progress

PropType
value?number

Current value. A value below 0 or above `max` is clamped to that range.

Typenumber
Default0
max?number

Value at which the bar is full. It must be above 0.

Typenumber
Default100
variant?"default" | "success" | "danger"

Gradient of the filled part.

Type"default" | "success" | "danger"
Default"default"
getValueLabel?(value: number, max: number) => string

Builds the text a screen reader says for the value. The default is the rounded percentage.

Type(value: number, max: number) => string
indicatorClassName / indicator-class?string

Additional classes for the filled part.

Typestring

Progress renders a <div> with the filled part inside it. The bar carries data-state, which is loading below max and complete at max. ProgressLabel is a <div> and accepts its native attributes. progressVariants gives the gradient classes to an element of your own.

Accessibility

The bar has role="progressbar" with aria-valuemin, aria-valuemax and aria-valuenow. It also has aria-valuetext, which is the result of getValueLabel. The bar has no name of its own. Give it an aria-label, or an aria-labelledby that points at the visible label. The variant colour is not announced, so put a failure or a limit in the text too.

Tokens

Progress Bar reads its colours, radii and motion from the --newt-* tokens installed with the library. Override a token and every component that reads it follows, including this one — see the token layer. In the plain HTML and CSS distribution the same component is newt-progress.

  • --newt-radius-full
  • --newt-bg-base
  • --newt-brand
  • --newt-duration-base
  • --newt-ease
  • --newt-online
  • --newt-dnd
  • --newt-text-muted