Overview
A progress indicator shows a value from 0 to 100. The circle draws it as a ring with the number in the middle, and a short text under the number. The bar draws it as a fill in a track, with a label above and a feedback message below. The circle can also show the value as a fraction, such as 3.75/5.
Pick another component when:
Markup
Variants
Color and Status have one row for the circle and one for the bar. Write the row whose element is in the markup. Status is not for Out of or Steps: they show their own count.
| Group | Option | Markup | On element | Use |
|---|---|---|---|---|
| Structure | Circle (default) | — | — | A value that is the focus of the view: a dashboard figure or a completion rate |
| Structure | Steps (hint: Steps done out of all, such as 2 / 4) | canon #progress-steps |
— | Steps done out of all the steps, in the stepper’s ring style. data-num and data-max replace data-value |
| Structure | Out of (hint: A score read as a fraction, such as a GPA) | canon #progress-out-of |
— | A score read as a fraction: a GPA, a rating. data-num and data-max replace data-value |
| Structure | Bar | canon #progress-bar |
— | A task the user waits for: an upload or a form to complete |
| Circle size | SM | — | .nds-progress-circle |
64px, a circle with no size class. The text under the number does not show |
| Circle size | MD | .nds-md |
.nds-progress-circle |
80px. The text under the number does not show |
| Circle size | LG (default) | .nds-lg |
.nds-progress-circle |
120px |
| Circle size | XL | .nds-xl |
.nds-progress-circle |
160px |
| Circle size | 2XL | .nds-2xl |
.nds-progress-circle |
200px. A hero figure |
| Bar size | SM | .nds-sm |
.nds-progress-bar |
4px track. Beside other content |
| Bar size | MD | — | .nds-progress-bar |
8px track. A bar with no size class is MD |
| Bar size | LG (default) | .nds-lg |
.nds-progress-bar |
16px track, with the percentage in the fill |
| Color | Neutral | .nds-neutral |
.nds-progress-circle |
The neutral color, not the primary color. Use it when the value is not a brand figure |
| Color | Neutral | .nds-neutral |
.nds-progress-bar |
The same, on a bar |
| Status | None (default) | — | — | The task is running |
| Status | Success | [data-status="success"] |
.nds-progress-circle:not([data-num]) |
The task is done. The fill goes to 100% in the success color. The circle shows the success icon in place of the number |
| Status | Success | [data-status="success"] |
.nds-progress-bar |
The same, on a bar. The feedback icon turns to success |
| Status | Error | [data-status="error"] |
.nds-progress-circle:not([data-num]) |
The task failed. The fill stays and turns to the error color. The circle shows the error icon in place of the number |
| Status | Error | [data-status="error"] |
.nds-progress-bar |
The same, on a bar. The feedback icon turns to error |
Behavior
Out Of
The circle shows a score as a fraction, such as 3.75/5, in place of a percentage. Set data-num and data-max on the circle instead of data-value. The script writes the two numbers and fills the ring to their ratio. When both are set, they win over data-value.
Steps
The circle shows steps done out of all the steps, such as 2 / 4, the same as the ring of a radial Stepper. Set data-num and data-max, as for Out of, and write nds-progress-steps in place of nds-progress-out-of. Use it for a task the user moves through outside a stepper, such as a journey shown on a card.
Status
data-status="success" fills the indicator to 100% in the success color, whatever its value. data-status="error" keeps the fill where it is and turns it to the error color. On a circle, the status icon takes the place of the number. On a bar, the feedback icon below the track changes. Out of takes no status: a score does not succeed or fail.
Percentage in the Bar
A large bar (nds-lg) shows the percentage inside the fill, at its end. Small and medium bars are too thin for text, so they show no number. Use a large bar when the user needs the exact value.
Built-in Features
-
Auto-initialization
The script starts every circle and bar that has
data-valueordata-num. No init call is needed. -
Data-Driven Values
Change
data-value,data-numordata-maxand the indicator redraws. A value above 100 shows as 100. -
Scroll-triggered Fill
The fill starts when half of the indicator is on the screen, so the user sees it move. With reduced motion, the value shows at once.
-
Smooth Transitions
The fill moves to each new value in 0.3 seconds, on the circle and the bar.
-
Scalable Text
The number, the text and the status icon grow with the circle, at every size class and at a custom
--progress-size. -
Screen Reader Value
The script adds
role="progressbar"if it is missing. It keepsaria-valuenow,aria-valueminandaria-valuemaxin step with the value. A screen reader reads the value before the fill starts. -
Programmatic Control
NDS.Progress.setValue()andNDS.Progress.setOutOf()change the value from code.
Best Practices
- Name every indicator: point
aria-labelledbyat its label or text. Without a name, a screen reader reads only a number. - Set the value with
data-value, not with--progress-valueinstyle. The script reads the attribute, and the screen reader value comes from it. - Keep the circle text to one or two words. It shows only at LG and larger.
- Write a bar label that names the task, such as the file name, and a feedback message that says what happens now.
- Set
data-status="success"only when the task is done. - Do not use a progress indicator for a wait with no known length. Use Loading.
API
Data Attributes
| Attribute | Element | Effect |
|---|---|---|
data-value |
.nds-progress-circle, .nds-progress-bar |
The value, 0 to 100 |
data-num, data-max |
.nds-progress-circle |
The fraction for Out of and Steps. Both are needed. They win over data-value |
data-status |
.nds-progress-circle, .nds-progress-bar |
success or error. See Status under Behavior |
aria-labelledby |
.nds-progress-circle, .nds-progress-bar |
The id of the element that names the indicator |
For Out of, the script sets aria-valuemax to data-max, not 100.
CSS Custom Properties
Set these in the style of the circle or the bar. --progress-size wins over the circle’s size classes, and it also reaches the circle from a parent. The bar’s size classes set --progress-height on the bar, so a value set on a parent does not reach it.
| Property | Default | Controls |
|---|---|---|
--progress-value |
0 |
The fill, 0 to 100. The script sets it from data-value |
--progress-color |
var(--background-primary) |
The fill color |
--progress-size |
64px |
Circle only. The diameter |
--progress-track-color |
var(--background-neutral-light) |
The ring behind the circle’s fill, or the track of the bar |
--progress-circumference |
62.83 |
Circle only. The ring length for an SVG circle with r="10". Change it only with a different radius |
--progress-height |
8px |
Bar only. The track height |
Tokens
Set a token at :root, or on a wrapper to reach every progress indicator inside it. Give a token with a Dark mode value a dark override too: see Tokens. The neutral fill is the color of .nds-neutral. The neutral ring in a Stepper uses it too.
Source: the progress group in _sass/tokens/_components.scss.
| Token | Preview | Value |
|---|---|---|
--progress-background-primary | var(--background-primary)Dark mode var(--colors-primary-500) | |
--progress-background-neutral | var(--colors-neutral-700)Dark mode var(--colors-neutral-200) | |
--progress-text-primary | var(--text-oncolor-primary) |
It also reads these shared tokens. A change to one also changes other components.
Source: the var() reads in _sass/components/_progress.scss.
| Token | Preview | Value |
|---|---|---|
--background-surface-oncolorRead by --progress-color | var(--colors-base-white) | |
--background-neutral-lightRead by --progress-track-color, background-color | var(--colors-neutral-100)Dark mode var(--colors-alpha-white-10) | |
--background-successRead by --progress-color | var(--colors-green-600) | |
--background-errorRead by --progress-color | var(--colors-red-600) | |
--text-defaultRead by color | var(--colors-base-black)Dark mode var(--colors-neutral-200) | |
--text-primary-paragraphRead by color | var(--colors-neutral-700)Dark mode var(--colors-neutral-300) | |
--text-secondary-paragraphRead by color | var(--colors-neutral-500)Dark mode var(--colors-neutral-400) | |
--text-oncolor-primaryRead by color, --feedback-symbol-color | var(--colors-base-white) |
JavaScript
The NDS.Progress script loads after the page shows. Until it loads, each call loads it and returns a promise of the result, so await a call whose result you use.
| Method | Effect |
|---|---|
NDS.Progress.init() |
Starts every indicator on the page. Call it after you add indicators |
NDS.Progress.setValue(el, value) |
Sets data-value |
NDS.Progress.setOutOf(el, num, max) |
Sets data-num and data-max |
NDS.Progress.create(el) |
Draws one indicator from its attributes now, with no wait for scroll |
NDS.Progress.destroy(el) |
Stops a reveal that is still waiting for the indicator to scroll into view |
The component fires no events. The methods only write the attributes, so writing them yourself works the same. The full API is in the banner of _js/nds-progress.js.