Skip to content
Slotted

Skeleton

Reserves the boxes of content that is still loading, so the loaded screen lands in the same place.

Loading the dock supervisor

Installation

The packages are a 0.x beta on npm, and their public API changes between beta releases without deprecation. One line installs the binding and the default theme.

bash
pnpm add @slotted/react @slotted/theme @slotted/themes
tsx
import { Skeleton, SkeletonText, SkeletonRegion,  SkeletonDefaultsProvider } from '@slotted/react';

A placeholder inside a region

Skeleton draws one placeholder. With no props it is a line of text: as wide as its container and as tall as the type around it. SkeletonRegion owns the wait for everything inside it. It carries aria-busy, announces messages.label once through a visually hidden status element, and passes its loading state to every placeholder inside. The placeholders are aria-hidden and inert, so a screen reader hears one message and focus never lands on a bar. This region has no loading prop, so it stays loading; the examples further down switch it.

Shapes

shape states what the placeholder stands for: text is a line of type, block is a box with the height you give it (blockSize), and circle and square are the two boxes an avatar can be. inlineSize and blockSize reserve a width and a height in any CSS length. In React a bare number is pixels.

Avatar sizes

size applies to circle and square and reads the Avatar scale: xs, sm, md, lg and xl, with md as the default. A placeholder and the Avatar of the same size occupy the same box. text takes its height from the type around it and block takes it from blockSize, so neither reads size.

Paragraphs

SkeletonText reserves the rows of a paragraph. Each row is one line box of the type it sits in, so three rows occupy the three lines the words will. lines sets the count and defaults to 3. When there is more than one row the last one is drawn short, 62% wide unless lastLineSize says otherwise; a single row is never shortened. inlineSize narrows the whole paragraph.

Type and direction

A placeholder takes its height from the type around it, so one placed inside a Heading is exactly as tall as that heading at its size, with no height written anywhere. Widths and the short last row are logical, so a paragraph under dir="rtl" starts at the right edge.

Animation

animation chooses how the wait moves: shimmer sends a band across the placeholder and is the default, pulse dims and restores the fill, and none is still. A region passes its value to every placeholder inside it, and a placeholder’s own animation wins. Under prefers-reduced-motion all three stop and the shape stays.

shimmer
pulse
none

Covering real content

Put content inside a Skeleton and the box takes that content’s own geometry, hides it, and draws the placeholder over it. When loading ends the box stops taking part in layout and the content stays exactly where it was, so the reserved space cannot differ from what replaces it. Cover one element per box, such as a Text or an Avatar, so that the box and the element are the same size. Here the boxes follow the region: a Skeleton with no loading of its own uses the nearest region’s answer. The button replays a first load of 1.5 seconds.

Loading the invoice

Loading a list

A list that is being fetched keeps its chrome painted and reserves only the rows that are coming. The heading and the button render for real. Each row renders the same layout in both states: a circle at the avatar size, and a Skeleton inside each Text, with widths that differ from row to row, so the line height is the one the text will take. loadedLabel makes the region announce a second message when the content arrives; without it the region is silent on arrival. The button replays the first load.

Warehouse team

Loading the team

Loading in pieces

loading on a Skeleton or SkeletonText overrides the region for that box only. Data that arrives in pieces shows each piece as it lands: here the status is known and shown, while the carrier and the notes are still placeholders. With loading={false} in React and [loading]="false" in Angular, the box is no longer aria-hidden or inert.

Loading shipment SO-10482

Shipment SO-10482

In transit

Delay and minimum duration

delay is how long the wait must last before anything is painted, and minDuration is how long a placeholder that did appear stays. Both default to 0. Set them once for the application, 200 and 400 milliseconds being the recommended pair: SkeletonDefaultsProvider in React and provideSkeletonDefaults in Angular. The provider also takes animation, lastLineSize, live and loadedLabel, and a prop on a region or a box still wins. onReveal in React and (reveal) in Angular fire when the placeholders are actually withdrawn, which is later than loading turning false whenever minDuration still holds them. Cover the content, as here, so that it stands during the delay and returns only when the placeholder goes: a page that swaps the two on its own loading follows neither time. The first button responds before the delay, so nothing is drawn and the counter does not move. The second responds 50 ms after the placeholder appears, which stays its 400 ms. The third draws the placeholder after 200 ms and withdraws it with the response.

Pallet PL-4821 left dock 6 at 14:05.
Placeholders withdrawn: 0

Silent regions

live="off" removes the status element, so the region keeps aria-busy and says nothing. Use it where the surrounding screen already announces the wait, or where the content is decorative, such as a strip of avatars. live defaults to polite.

Recently active

Choosing the indicator

A skeleton answers a wait whose structure is known before the data arrives: a list, a table, a card, a form. Other waits take another indicator.

  • A control that started the work and stays on screen uses its own loading, as Button does.
  • Work that reports how much is done uses the progress indicator.
  • A region that is already painted and is being replaced uses the loading overlay.
  • Refreshing data that is already on screen keeps its values and takes aria-busy on the region, instead of returning to a skeleton on every refresh.

Two indicators never answer the same wait in the same region. A region that finishes loading with nothing to show renders an empty state, never an empty skeleton, and an error replaces the placeholders.

Accessibility

  • Every placeholder carries aria-hidden="true" and inert while it is painted. Reading out the absence of something is noise, and focus must not fall into content that is not ready — a covered button is unreachable rather than reachable and useless.
  • An aria-hidden written by hand on a placeholder is kept, so a placeholder that has to stay announced can be.
  • The region carries aria-busy="true" while it waits, which is the platform’s own answer: ARIA 1.2 asks an author to set it on the container before the first change and clear it when the last change is complete. The ARIA Authoring Practices Guide has no pattern for a skeleton.
  • One region is one announcement. A visually-hidden role="status" holds the label while waiting and is emptied afterwards, and emptying a live region announces nothing, so twelve placeholders do not become twelve messages. loadedLabel opts into a second.
  • Under prefers-reduced-motion the loop stops rather than shortening: an infinite animation that hurries is still moving. animation="none", set once through the provider, is the author-side mechanism WCAG 2.2 SC 2.2.2 asks for.
  • The placeholder is visible in all three color schemes. The fill is the unavailable surface shifted slightly toward the text color, and a hairline rim takes over in high contrast, where that surface is the page’s own white.

API

Skeleton

Props

shape'text' | 'block' | 'circle' | 'square'Default text
What the placeholder stands for: a line of type, a block of content, a round avatar or a square avatar.
size'xs' | 'sm' | 'md' | 'lg' | 'xl'Default md
The avatar scale, read by the circle and square shapes. Text takes its height from the surrounding type, and block takes it from blockSize or from its content.
inlineSize, blockSizenumber | string
On Skeleton, SkeletonTextThe reserved geometry along the inline and block axes. A bare number is pixels. SkeletonText takes inlineSize only. A box that covers content takes that content’s size unless you state one.
loadingbooleanDefault true
On Skeleton, SkeletonText, SkeletonRegionWhether the content is still on its way. On a box, leaving it unset hands the decision to the nearest region.
linesnumberDefault 3
On SkeletonTextHow many rows of the paragraph to reserve.
lastLineSizestringDefault 62%
On SkeletonTextThe width of the last row. It applies only when there is more than one row.
animation'shimmer' | 'pulse' | 'none'Default shimmer
On Skeleton, SkeletonText, SkeletonRegionHow the wait moves. A region passes its value to every placeholder inside it.
live'polite' | 'off'Default polite
On SkeletonRegionWhether the region announces the wait. The value off leaves the status element out.
messagesPartial<SkeletonMessages>
On SkeletonRegionWords laid over the language in force, key by key. The label key is what a screen reader hears once, while the region waits.
loadedLabelstring
On SkeletonRegionWhat a screen reader hears when the content arrives. The region is silent on arrival unless this is set.
delaynumberDefault 0
On SkeletonRegionMilliseconds the wait must last before anything is painted.
minDurationnumberDefault 0
On SkeletonRegionMilliseconds a placeholder that did appear stays painted before it is withdrawn.

Events

NamePayloadWhen
onRevealvoidThe placeholders are actually withdrawn, which is later than loading turning false whenever minDuration still holds them. Use it to move focus on.

Composition

childrenReactNode
Covered rather than replaced: the box takes the content’s own geometry, hides it, and reveals it untouched when loading ends.
render(props) => ReactNode
On Skeleton, SkeletonText, SkeletonRegionSubstitutes the rendered element. Every data attribute and the geometry style are passed to it.
refRef<HTMLSpanElement | HTMLDivElement>
On all threeReaches the native element. The props of each part are the props of that element, extended.
SkeletonDefaultsProviderSkeletonDefaults
On ApplicationSets animation, delay, minDuration, loadedLabel, lastLineSize and live once for everything below it. A prop on a region or a box still wins.

Parts

PartElementRequiredPurpose
rootspanYesOne placeholder box, rendered by Skeleton. Empty it draws the geometry shape and size describe; with children it takes their geometry and covers them.
textdivYesThe rows of a paragraph, rendered by SkeletonText. A grid whose tracks are exactly one line box, so the rows occupy the lines the words will.
linespanYesOne row inside text, repeated lines times. The last of several is drawn short; a lone row is not.
regiondivYesThe loading fact for a subtree, rendered by SkeletonRegion. Carries aria-busy, the timing, and the animation phase every placeholder inside it reads.
announcementspanYesThe one visually-hidden role="status" per region. Holds the label while waiting and is emptied afterwards, so a load announces once.

Theming

Each token is a CSS custom property: set it in a theme, or on any element to retune every skeleton inside it.

Skeleton tokens

TokenDefault
--slotted-skeleton-block-sizevar(--_line)
--slotted-skeleton-border-colorvar(--slotted-border-subtle, ButtonBorder)
--slotted-skeleton-border-widthvar(--slotted-border-width-thin, 1px)
--slotted-skeleton-fillcolor-mix( in oklab, var(--slotted-disabled-background, ButtonFace) 92%, var(--slotted-text, CanvasText) )
--slotted-skeleton-highlight-colorcolor-mix(in oklab, var(--_fill) 86%, var(--slotted-text, CanvasText))
--slotted-skeleton-inline-size100%
--slotted-skeleton-last-line-size62%
--slotted-skeleton-line-size1cap
--slotted-skeleton-min-block-size1lh
--slotted-skeleton-phase0
--slotted-skeleton-radiusvar(--slotted-radius-md, 6px)
--slotted-skeleton-row-size1lh
--slotted-skeleton-sizevar(--slotted-avatar-size-md, 36px)
--slotted-skeleton-trough-colorcolor-mix(in oklab, var(--_fill) 60%, var(--slotted-surface-sunken, Canvas))

Theme tokens it reads

TokenDefault
--slotted-avatar-size-lgcomfortable 48px · compact 42px · dense 36px
--slotted-avatar-size-mdcomfortable 36px · compact 32px · dense 28px
--slotted-avatar-size-smcomfortable 28px · compact 26px · dense 24px
--slotted-avatar-size-xlcomfortable 64px · compact 56px · dense 48px
--slotted-avatar-size-xscomfortable 24px · compact 22px · dense 20px
--slotted-border-subtleSet per scheme by the theme
--slotted-border-width-thin1px
--slotted-disabled-backgroundSet per scheme by the theme
--slotted-duration-loop-slow1.6s
--slotted-radius-full9999px
--slotted-radius-md6px
--slotted-surface-sunkenSet per scheme by the theme
--slotted-textSet per scheme by the theme