Skip to content

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

Components

Free

Circular Progress for Svelte

A circular progress ring for Svelte on Ark UI, sized in pixels for buttons and table cells, with the percent inside and a spinning indeterminate state.

On this page9 sections
UI library: Ark UI

Circular Progress draws a known amount of work as a ring that fills clockwise from the top, small enough for a button, an avatar or a table cell. It can print the percent inside, and it spins while the amount is still unknown.

A transfer with room to span the page reads better as a Progress bar, and work with no amount at all is a job for a Spinner.

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

Circular Progress anatomy: root, label, track, range, value

Usage

import { useEffect, useState } from "react";
import { CircularProgress } from "@/components/ui/circular-progress";
const Example = () => {
  const [progress, setProgress] = useState(24);

  useEffect(() => {
    const timer = setTimeout(() => {
      setProgress(72);
    }, 500);

    return () => {
      clearTimeout(timer);
    };
  }, []);

  return <CircularProgress value={progress} />;
};

The timer stands in for real work: half a second after mount it moves value from 24 to 72, and the arc slides to the new number.

Accessibility

The ring is an svg with the progressbar role, carrying aria-valuenow, aria-valuemin and aria-valuemax. A CircularProgressLabel names it through aria-labelledby, and an aria-label or aria-labelledby passed to CircularProgress goes to the ring. With none of them, Ark UI names the ring by its value text, "72%" or, while indeterminate, "loading...", which says nothing about the task when several rings share a page. CircularProgressValue is a polite live region, read again each time the number changes. Under reduced motion, new values jump instead of sliding, and the indeterminate ring holds still.

Demos

Controlled

A minus and a plus button step the ring by 10 between 0 and 100, starting at 55, and the arc slides to each new number over 300 milliseconds. Pass value from your own state like this whenever something on the page changes the amount, which covers nearly every real use.

Preview width

Indeterminate

The ring has indeterminate set and a label above it reading "Establishing connection…", so a short arc, 30% of the circle, spins in place. Show it while the size of the job is unknown, then pass a number the moment one arrives. The label is what tells this wait apart from any other on the page.

Preview width

Min max

The scale runs from 10 to 30 with defaultValue at 20, so the ring is half full and CircularProgressValue prints 50%, the share of the range rather than the raw number. Set min and max when the work is counted in pages or steps. To print the count itself, give CircularProgressValue your own text as its content.

Preview width

Root provider

useCircularProgress creates the state with a defaultValue of 50, and CircularProgressRootProvider draws it. A Set to max button outside the ring calls setToMax, and a line above prints the current value. Use the hook when a sibling has to read the value or call a helper, and plain value when nothing outside the ring touches it.

Preview width

Size

Three rings 24, 32 and 40 pixels across, filled to 35, 62 and 84. size sets the diameter in pixels, 32 by default, while the stroke stays at its default of 4 on all three. Use 24 inside a dense table row or beside small text, and grow the ring once a number has to fit inside it.

Preview width

Thickness

Three pairs of size and thickness: 24 with 2, 66 with 6, and 100 with 8. The stroke is set apart from the diameter, so a small ring can stay a hairline while a large one carries a heavy arc. Grow them together, because the default 4-pixel stroke turns a 100-pixel ring into a thin outline.

Preview width

View

Two buttons drive a ring that starts at 40: Complete sets it to 100 and Indeterminate sets it to null. Three CircularProgressView parts, one per state, print Loading, Done or Wait above the ring, and only the one matching the current state shows. Use views when finishing should change the words as well as the arc.

Preview width

With label

A ring at 42 with CircularProgressLabel reading "Uploading" above it and CircularProgressValue printing 42% inside, at a size of 66 so the digits clear the stroke. Use a label when several rings share a screen and each needs a caption. The label also becomes the ring's name for screen readers.

Preview width

With value

Only the percent, centered inside a 66-pixel ring with a 5-pixel stroke and no caption. Pick it when a file name or a heading beside the ring already says what is loading. CircularProgressValue formats the number as a percent, and formatOptions on CircularProgress changes that format, to show one decimal place for example.

Preview width

FAQ

How do I show the percentage inside a Circular Progress?

Put CircularProgressValue inside CircularProgress. It is positioned over the ring at the same size and centers the percent in it, as the With value demo shows. Give it your own text as its content, such as "3 of 5", and that replaces the percent.

At the default size of 32 the inner circle is 24 pixels wide, so "100%" runs into the stroke. Raise size to 48 or more whenever a number sits inside.

How do I update the Circular Progress value in Svelte?

Keep the number in state and pass it as value, and the arc slides to each new one over 300 milliseconds. It runs from min to max, 0 to 100 unless you set them, so a job counted in steps can pass the step and its total as they are. A number outside that range is held at the nearest end.

Pass a number from the first render. With no value and no defaultValue, Ark UI starts the ring halfway between min and max, which shows as 50% before your data arrives. Pass null instead when you'd rather show it spinning.

How do I make an indeterminate Circular Progress?

Set indeterminate to true on CircularProgress, or pass null as value. The arc shrinks to 30% of the circle and spins, as in the Indeterminate demo, and the ring drops aria-valuenow until you pass a number again.

CircularProgressRootProvider has no indeterminate prop, so with useCircularProgress set the value to null instead. When the work never has a number at all, a Spinner is the lighter choice.

How do I change the size, thickness or color of a Circular Progress?

Set size for the diameter and thickness for the stroke, both in pixels, 32 and 4 by default. The two are separate, so grow the stroke along with the ring, as the Thickness demo does.

The colors are classes on the circles inside: the track is stroke-input and the arc is stroke-primary, in components/ui/circular-progress. For one ring, reach the arc from the classes you pass to CircularProgress, such as **:data-[slot=circular-progress-range]:stroke-emerald-500.

Can a Circular Progress show different content when it completes?

Yes, with one CircularProgressView per state. Set each one's state to loading, complete or indeterminate, and only the view matching the ring's state is visible, while the others stay in the page with hidden set. The View demo swaps Loading for Done.

The ring counts as complete only when value equals max exactly, so a job whose last report is 99.6 never shows its complete view. Pass max itself once the work is done.

How do I give a Circular Progress a name screen readers read?

Put a CircularProgressLabel inside CircularProgress, and the ring takes its text as its name through aria-labelledby, as in the With label demo. Without a visible caption, pass aria-label to CircularProgress, and it goes to the ring.

With neither, Ark UI names the ring by its value text, "42%". Pass translations with a value function to change that text, such as "Uploading, 42%". The function receives the value, min, max and percent, so it can also say "Step 3 of 5" for a ring counted in steps.

Should I use a Circular Progress or a Progress bar?

Use a Circular Progress where space is tight: inside a button, over an avatar, in a table cell or a card's corner. A Progress bar fits when there's room for a full-width track, such as a file upload or a setup flow, because a length is easier to compare than an arc.

API Reference

CircularProgress

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

PropType
value?number | null

The controlled value of the progress bar.

Type
number | null
defaultValue?number | null

The initial value of the progress bar when rendered. Use when you don't need to control the value of the progress bar.

Type
number | null
Default
50
onValueChange?(details: ValueChangeDetails) → void

Callback fired when the value changes.

Type
(details: ValueChangeDetails) → void
Parameters

details – { value: number | null }

Returns
void
dir?"ltr" | "rtl"

The document's text/writing direction.

Type
"ltr" | "rtl"
Default
"ltr"
formatOptions?Intl.NumberFormatOptions

The options to use for formatting the value.

Default
{ style: "percent" }
id?string

The unique identifier of the machine.

ids?object

The ids of the elements in the progress bar. Useful for composition.

Type
{ root?: string; track?: string; label?: string; circle?: string }
indeterminate?boolean

Shows indeterminate progress (value={null}). * * @default false.

Default
false
locale?string

The locale to use for formatting the value.

Default
"en-US"
max?number

The maximum allowed value of the progress bar.

Default
100
min?number

The minimum allowed value of the progress bar.

Default
0
orientation?"horizontal" | "vertical"

The orientation of the element.

Type
"horizontal" | "vertical"
Default
"horizontal"
size?number

Width and height of the circle, in pixels.

Default
32
thickness?number

Stroke width of the circle, in pixels.

Default
4
translations?object

The localized messages to use.

Type
{ value?: (details: ValueTranslationDetails) → string }
asChild?Snippet<[PropsFn]>

Render your own element: a snippet that gets the part's props to spread on it.

Type
Snippet<[PropsFn]>
class?string

Merged with the part's classes.

AttributeType
data-max?string
data-orientation?string

The orientation of the progress.

data-state"indeterminate" | "loading" | "complete"

"indeterminate", "loading" or "complete".

Type
"indeterminate" | "loading" | "complete"
data-value?string

The value of the item.

CSS variableType
--circumferencestring

The circumference value for the root.

--offsetstring

The offset position of the element.

--percentstring

The percent value for the root.

--radiusstring

The border radius value.

CircularProgressLabel

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

PropType
asChild?Snippet<[PropsFn]>

Render your own element: a snippet that gets the part's props to spread on it.

Type
Snippet<[PropsFn]>
class?string

Merged with the part's classes.

AttributeType
data-orientation?string

The orientation of the label.

CircularProgressValue

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

PropType
asChild?Snippet<[PropsFn]>

Render your own element: a snippet that gets the part's props to spread on it.

Type
Snippet<[PropsFn]>
class?string

Merged with the part's classes.

CSS variableType
--sizestring

CircularProgressView

<span> data-slot="circular-progress-view"

PropType
state"indeterminate" | "loading" | "complete"

The state it shows in: loading, complete or indeterminate; it renders only then.

Type
"indeterminate" | "loading" | "complete"
asChild?Snippet<[PropsFn]>

Render your own element: a snippet that gets the part's props to spread on it.

Type
Snippet<[PropsFn]>
class?string

Merged with the part's classes.

AttributeType
data-state"indeterminate" | "loading" | "complete"

"indeterminate", "loading" or "complete".

Type
"indeterminate" | "loading" | "complete"

CircularProgressTrack

<svg> data-slot="circular-progress-circle"

PropType
size?number

Width and height of the circle, in pixels.

Default
32
thickness?number

Stroke width of the circle, in pixels.

Default
4
asChild?Snippet<[PropsFn]>

Render your own element: a snippet that gets the part's props to spread on it.

Type
Snippet<[PropsFn]>
class?string

Merged with the part's classes.

AttributeType
data-max?string
data-orientation?string

The orientation of the circle.

data-state"indeterminate" | "loading" | "complete"

"indeterminate", "loading" or "complete".

Type
"indeterminate" | "loading" | "complete"
CSS variableType
--circumferencestring
--percentstring

The value as a percentage of the range.

CircularProgressCircleTrack

<circle> data-slot="circular-progress-track"

PropType
asChild?Snippet<[PropsFn]>

Render your own element: a snippet that gets the part's props to spread on it.

Type
Snippet<[PropsFn]>
AttributeType
data-orientation?string

The orientation of the circletrack.

CSS variableType
--circumferencestring

CircularProgressCircleRange

<circle> data-slot="circular-progress-range"

PropType
asChild?Snippet<[PropsFn]>

Render your own element: a snippet that gets the part's props to spread on it.

Type
Snippet<[PropsFn]>
AttributeType
data-state"indeterminate" | "loading" | "complete"

"indeterminate", "loading" or "complete".

Type
"indeterminate" | "loading" | "complete"
CSS variableType
--circumferencestring

CircularProgressRootProvider

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

PropType
valueUseProgressReturn

What useCircularProgress() returns: the state and API, made outside the component to control it.

size?number

Width and height of the circle, in pixels.

Default
32
thickness?number

Stroke width of the circle, in pixels.

Default
4
asChild?Snippet<[PropsFn]>

Render your own element: a snippet that gets the part's props to spread on it.

Type
Snippet<[PropsFn]>
class?string

Merged with the part's classes.

useCircularProgress

CircularProgressContext