Skip to main content
Login

Sign in to access your account

Loading - National Design System

A loading state dims the content of a container and shows a spinner over it while the content updates

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:

  • the task has a known length: Progress
  • the content finished loading and is empty: Empty

Markup

Preview
Application status

The status of your application updates every few minutes.

<div class="nds-loading" aria-busy="true"> <div class="nds-card nds-stroke"> <div class="nds-card-content"> <div class="nds-card-text"> <span class="nds-card-title">Application status</span> <p class="nds-card-description">The status of your application updates every few minutes.</p> </div> </div> </div> </div>

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.

Card Title Card Subtitle

Short description of this card content goes here for demonstration.

<div class="nds-card nds-stroke nds-loading" aria-busy="true"> <div class="nds-card-header"> <div class="nds-card-featured-icon"> <span class="nds-featured-icon nds-circle"> <i class="hgi hgi-stroke hgi-stars"></i> </span> </div> </div> <div class="nds-card-content"> <div class="nds-card-text"> <span class="nds-card-title">Card Title</span> <span class="nds-card-subtitle">Card Subtitle</span> <p class="nds-card-description">Short description of this card content goes here for demonstration.</p> </div> </div> </div>

Built-in Features

  • CSS Only

    The spinner is the ::after of the container. No script and no extra element are needed.

  • Interaction Blocked

    The container gets pointer-events: none and user-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 sets aria-busy itself.
  • 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-xxs or nds-xs in a table cell, nds-xl or nds-2xl over a whole page.
  • Use nds-oncolor only on a surface that is always dark or colored. In dark mode, the default and nds-neutral turn 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-loading on 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.

TokenPreviewValue
--background-primary
Read by --loading-color
var(--colors-primary-600)
--icon-default
Read by --loading-color

var(--colors-base-black)
Dark mode var(--colors-neutral-100)
--icon-oncolor
Read 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.

var list = document.querySelector('#results'); NDS.state.add(list, 'loading'); list.setAttribute('aria-busy', 'true'); fetch('/api/results').then(function () { NDS.state.remove(list, 'loading'); list.removeAttribute('aria-busy'); });

The code that copies the token to the class is in _js/nds-core.js, under Token mirrors.

Last Modified Date: 20/11/2026 - 04:53 PM
Was this page useful?
60% of users said Yes from 2843 Feedbacks