Skip to content

shadcn.io is an independent project built on shadcn/ui

Components

Free

Progress for Svelte UI SDK

A progress bar for Svelte on UI SDK that fills from the value you pass, for uploads and numbered steps, with an optional label and percent.

On this page9 sections

A progress bar shows how far a task with a known end has gotten: an upload, an import, the third of five setup steps. It fills from the value you pass and redraws when that number changes. It never watches the request itself.

When there's no number to report, a Spinner is the honest choice. For a ring that fits a tight corner, use Circular Progress, and when people should set the number themselves, a Slider.

Preview width

Installation

Sign in to get your install command
Free with an account. It carries your token, so the CLI installs everything in one go.

Anatomy

Progress anatomy: root, label, value, track, indicator

Usage

import { useEffect, useState } from "react";
import { Progress } from "@/components/ui/progress";
const ProgressDemo = () => {
  const [progress, setProgress] = useState(13);

  useEffect(() => {
    const timer = setTimeout(() => setProgress(66), 500);
    return () => clearTimeout(timer);
  }, []);

  return <Progress aria-label="Loading" className="w-[60%]" value={progress} />;
};

The timer stands in for real work: half a second after mount it moves value from 13 to 66, and the fill slides to match. In your app the number comes from the upload or the job that reports it. With no visible label, aria-label gives the bar its name.

Accessibility

Progress is the element with the progressbar role, and it carries aria-valuenow, aria-valuemin, aria-valuemax and an aria-valuetext such as "56%". ProgressLabel names the bar through aria-labelledby, and ProgressValue is hidden from screen readers, since the value text already says the same. When the design has no visible label, pass aria-label to Progress instead.

Demos

Label

An upload bar at 56%, with ProgressLabel reading "Upload progress" on one side and ProgressValue printing the percent on the other, both inside Progress. Use it when the page runs more than one task, or the bar sits far from the thing it measures. The label also becomes the bar's name for screen readers.

Preview width

Controlled

A bar at 50% with a Slider under it that writes into the same state, so dragging the thumb moves the fill. The slider stands in for the real source. In an app, value comes from an upload's progress events or from the step a setup flow is on. Reach for this pattern whenever the work can report how far it has gotten.

Preview width

RTL

The upload bar with an Arabic label and dir set to rtl on Progress. The label moves to the right, the percent to the left, and the fill grows from the right edge. Use it on an Arabic or Hebrew page, where setting dir on any parent turns every bar inside it the same way.

Preview width

FAQ

How do I update a Progress bar from a file upload in Svelte?

Keep the percent in state and pass it as value: the bar redraws on every change and never reads the request itself. For an upload, XMLHttpRequest reports bytes sent through upload.onprogress, and loaded / total * 100 is the number to store. fetch has no upload progress event, so a bar driven by it can only jump from start to finish.

With no value, Progress passes null to UI SDK and the bar shows as indeterminate, so pass 0 when the upload starts.

How do I show an indeterminate Progress bar when I don't know how long it will take?

Pass null as value, or leave it out. The bar drops aria-valuenow and aria-valuetext, and every part, from the root to the indicator, gets a data-indeterminate attribute.

The indicator then fills the whole track and pulses, so the bar reads as busy rather than empty or finished. The pulse is a fade, not movement, so it keeps running under reduced motion. For another look, change the indicator's classes for that state in components/ui/progress, or show a Spinner, which says "working" without a number.

How do I count steps instead of percent with the UI SDK Progress?

Set max on Progress to the number of steps and pass the current step as value: 3 with a max of 5 fills 60% of the track, and min moves the start when the count doesn't begin at 0. ProgressValue prints a percent unless you give it content of its own, such as "3 of 5", which replaces the number. That content receives the part's state, with the formatted text and the raw value.

How do I change what screen readers hear for the UI SDK Progress?

Pass translations with a value function, which receives the value, min, max and percent and returns the bar's aria-valuetext, such as "Step 3 of 5" in place of "60%". The visible ProgressValue keeps the number, so change it through its own content. To change the number for both, pass formatOptions with Intl.NumberFormat options: a percent style places value between min and max, and any other style formats value as it is.

How do I show a label and the percentage next to the Progress bar?

Put ProgressLabel and ProgressValue inside Progress, ahead of the track it renders for you, as the Label demo does. The root is a flex row that wraps, so the two share the first line with the value pushed to the far end, and the track takes the full width beneath them.

ProgressLabel also becomes the bar's accessible name, so it needs no aria-label.

How do I change the color or height of a Progress bar?

Progress renders its track and indicator for you, so reach them from the classes you pass to Progress, matching their data-slot. *:data-[slot=progress-track]:h-3 makes the track taller, and **:data-[slot=progress-indicator]:bg-emerald-500 recolors the fill. The first selector matches direct children only, and the indicator sits one level deeper, inside the track.

For a look every bar in the app should share, edit ProgressTrack and ProgressIndicator in components/ui/progress, which is your code once installed.

What happens when a Progress value goes past max?

UI SDK clamps it for the fill and for screen readers. A value above max fills the whole track and reports max, and one below min leaves it empty. Nothing breaks, but a bar sitting at 100% while work goes on points at max and value counting different things, such as kilobytes against bytes.

When should I use a Slider or a Circular Progress instead of a Progress bar?

Progress reports a number your code sets, and nobody can move it. When people should choose the value, such as a volume or a price ceiling, use a Slider, which takes focus and answers to the arrow keys.

Circular Progress shows the same kind of value as a ring, for a card corner or a button where a full-width bar won't fit. A Spinner covers work with no amount to measure, like waiting on a server response.

API Reference

Progress

<div> data-slot="progress"

PropType
valuenumber | null

How far the task has come. null while how far is unknown.

Type
number | null
debug?boolean

Logs every state change with its reason to the console, in development builds.

format?NumberFormat

How the value reads, for screen readers and ProgressValue: Intl.NumberFormat options, or a function of the value.

getAriaValueText?(formattedValue: string, value: number | null) → string

The text screen readers hear for the value, from the formatted value and the value itself (null while indeterminate).

Type
(formattedValue: string, value: number | null) → string
Parameters

formattedValue – string

value – number | null

Returns
string
getValueLabel?(value: number | null, details: GaugeLabelDetails<number | null>) → string

The text screen readers announce for the value, when the formatted value says too little, like "3 of 12 files". It receives the value, null while a progress bar is indeterminate, and details: the formatted value, its percent, min and max.

Type
(value: number | null, details: GaugeLabelDetails<number | null>) → string
Parameters

value – number | null

details – GaugeLabelDetails<number | null>

Returns
string
locale?Intl.LocalesArgument

The locale the value is formatted in. Defaults to the page's lang.

Default
"en-US"
max?number

The highest value.

Default
100
min?number

The lowest value.

Default
0
render?Snippet<[{ props, state, children }]>

Renders your own element: a snippet that gets the part's props to spread on it, its state, and children, its content.

Type
Snippet<[{ props, state, children }]>
class?string

Merged with the part's classes.

AttributeType
data-complete?string

Present once the value reaches max.

data-indeterminate?string

Present while the value is null: the task is under way, but how far is unknown.

data-progressing?string

Present while the value is below max.

CSS variableType
--progress-valuestring

Where the value sits between min and max, as a percentage, like 40%. Unset while indeterminate.

ProgressTrack

<div> data-slot="progress-track"

PropType
render?Snippet<[{ props, state, children }]>

Renders your own element: a snippet that gets the part's props to spread on it, its state, and children, its content.

Type
Snippet<[{ props, state, children }]>
class?string

Merged with the part's classes.

AttributeType
data-complete?string

Present once the value reaches max.

data-indeterminate?string

Present while the value is null: the task is under way, but how far is unknown.

data-progressing?string

Present while the value is below max.

ProgressIndicator

<div> data-slot="progress-indicator"

PropType
render?Snippet<[{ props, state, children }]>

Renders your own element: a snippet that gets the part's props to spread on it, its state, and children, its content.

Type
Snippet<[{ props, state, children }]>
class?string

Merged with the part's classes.

AttributeType
data-complete?string

Present once the value reaches max.

data-indeterminate?string

Present while the value is null: the task is under way, but how far is unknown.

data-progressing?string

Present while the value is below max.

ProgressRange

<div> data-slot="progress-indicator"

PropType
render?Snippet<[{ props, state, children }]>

Renders your own element: a snippet that gets the part's props to spread on it, its state, and children, its content.

Type
Snippet<[{ props, state, children }]>
class?string

Merged with the part's classes.

AttributeType
data-complete?string

Present once the value reaches max.

data-indeterminate?string

Present while the value is null: the task is under way, but how far is unknown.

data-progressing?string

Present while the value is below max.

ProgressLabel

<span> data-slot="progress-label"

PropType
render?Snippet<[{ props, state, children }]>

Renders your own element: a snippet that gets the part's props to spread on it, its state, and children, its content.

Type
Snippet<[{ props, state, children }]>
class?string

Merged with the part's classes.

AttributeType
data-complete?string

Present once the value reaches max.

data-indeterminate?string

Present while the value is null: the task is under way, but how far is unknown.

data-progressing?string

Present while the value is below max.

ProgressValue

<span> data-slot="progress-value"

PropType
children?| Snippet | (( formattedValue: string | null, value: number | null ) → Snippet)

Replaces the formatted value: a node, or a function of the formatted value ("indeterminate" while indeterminate) and the value.

Type
| Snippet | (( formattedValue: string | null, value: number | null ) → Snippet)
render?Snippet<[{ props, state, children }]>

Renders your own element: a snippet that gets the part's props to spread on it, its state, and children, its content.

Type
Snippet<[{ props, state, children }]>
class?string

Merged with the part's classes.

AttributeType
data-complete?string

Present once the value reaches max.

data-indeterminate?string

Present while the value is null: the task is under way, but how far is unknown.

data-progressing?string

Present while the value is below max.