Overview
Loading is a state, not an element. The nds-loading class goes on any container, and blocks clicks until you remove it. Most containers show a spinner. A component that has a skeleton shows gray bars in the shape of its content instead.
Pick another component when:
Markup
The status of your application updates every few minutes.
Variants
The size and color classes go on the element that carries nds-loading.
| Group | Option | Markup | On element | Use |
|---|---|---|---|---|
| Size | XXS | .nds-xxs |
.nds-loading |
20px spinner, 2px stroke. Small parts, such as a table cell |
| Size | XS | .nds-xs |
.nds-loading |
24px spinner, 2px stroke |
| Size | SM | .nds-sm |
.nds-loading |
28px spinner, 2px stroke |
| Size | MD (default) | — | .nds-loading |
32px spinner, 3px stroke. Most containers |
| Size | LG | .nds-lg |
.nds-loading |
36px spinner, 3px stroke |
| Size | XL | .nds-xl |
.nds-loading |
40px spinner, 4px stroke. Large areas |
| Size | 2XL | .nds-2xl |
.nds-loading |
44px spinner, 4px stroke. A whole page or panel |
| Color | Primary (default) | — | .nds-loading |
The primary color on a light surface. White in dark mode |
| Color | Neutral | .nds-neutral |
.nds-loading |
Black on a light surface, white in dark mode. Use it where the primary color clashes with the content |
| Color | On color (hint: White spinner for a dark or colored surface) | .nds-oncolor |
.nds-loading |
White in every mode. Use it on a surface that is always dark or colored, such as a primary banner. On a white surface the spinner does not show. Inside an on-color area (data-theme="dark oncolor"), the spinner already takes this look: skip the class |
Behavior
Spinner
A container that has no skeleton of its own shows a spinner. Its children fade to 15% opacity, and the spinner turns in the center of the container. The size and color classes in the builder change only the spinner.
Skeleton
A component that has a skeleton, such as a card, a table or tabs, replaces its text with gray bars in the shape of its content. The bars pulse, the children do not fade, and no spinner shows. Put nds-loading on a grid of cards to turn every card in it into a skeleton. Each component’s page shows its own skeleton.
Short description of this card content goes here for demonstration.
Built-in Features
-
CSS Only
The spinner is the
::afterof the container. No script and no extra element are needed. -
Interaction Blocked
The container gets
pointer-events: noneanduser-select: none, so the user cannot click or select the content while it loads. -
Reduce Motion
The spinner keeps turning when the user turns on reduce motion in the accessibility panel. It shows that work is in progress, so it is not decoration.
-
Buttons and Fields
On a button, the spinner takes the button's colors and hides the label, so the button keeps its size. Form fields skip this spinner and show their own.
Best Practices
- Put
aria-busy="true"on the container while it loads, and remove it with the class. The spinner is CSS only, so a screen reader does not announce it. A component that shows its own loading state setsaria-busyitself. - Put the class on the smallest container that updates, not on the whole page.
- Keep the content in place while it loads. The dim shows the user what is about to change.
- Match the size to the container:
nds-xxsornds-xsin a table cell,nds-xlornds-2xlover a whole page. - Use
nds-oncoloronly on a surface that is always dark or colored. In dark mode, the default andnds-neutralturn white on their own. - Do not add a size or a color class to a component that has a skeleton. It shows no spinner.
- On a form field, put
nds-loadingon its.nds-form-container. The field shows its own spinner in place of its action buttons, not an overlay. See Forms.
API
Other Classes
| Class | Element | Effect |
|---|---|---|
nds-md |
.nds-loading |
The same as the default size |
Data Attributes
| Attribute | Element | Effect |
|---|---|---|
data-state~="loading" |
any container | The same as the nds-loading class. The core script adds the class when the token is set and removes it when the token goes. The CSS reads only the class, so this form needs the NDS script. Use it on an element whose other states a script already sets with data-state |
CSS Custom Properties
Set these on the loading container, or on a parent.
| Property | Default | Controls |
|---|---|---|
--loading-color |
var(--background-primary), var(--icon-oncolor) in dark mode |
Spinner arc color |
--loading-track |
var(--colors-alpha-black-10), var(--colors-alpha-white-20) in dark mode |
Spinner ring color |
--loading-size |
32px |
Spinner diameter. It wins over the size classes |
--loading-border |
3px |
Spinner stroke width. It wins over the size classes |
--loading-opacity |
0.15 |
Opacity of the children while the container loads |
Tokens
It reads these shared tokens. A change to one also changes other components: see Tokens.
Source: the var() reads in _sass/components/_loading.scss.
| Token | Preview | Value |
|---|---|---|
--background-primaryRead by --loading-color | var(--colors-primary-600) | |
--icon-defaultRead by --loading-color | var(--colors-base-black)Dark mode var(--colors-neutral-100) | |
--icon-oncolorRead by --loading-color | var(--colors-base-white) |
JavaScript
Loading has no script and no events. To turn it on and off from code, set the loading token with NDS.state.
The code that copies the token to the class is in _js/nds-core.js, under Token mirrors.