How it works
Each block is the text colour at 7% opacity (8% in dark), so it reads the same on a card and on a filled panel. The highlight is an ::after band moved with transform rather than background-position, and every block shares one global phase through a negative animation-delay, so blocks mounted at different moments still sweep together. Build the skeleton from the same rows and sizes as the real widget. SkeletonSwap keeps both layers in one grid cell while it cross-fades, so the container never collapses, and unmounts the skeleton after it has faded.
Use it for
- First load of content with a predictable structure, such as lists, cards and detail pages, so people see the layout first.
- Pull to refresh or refetching after a filter change, instead of a full-page spinner.
- Areas that usually take more than 300ms; faster requests should show the result directly.
Look elsewhere when
- Feedback for actions such as submit or save: use the loading state inside the button.
- Content with an unpredictable structure (unknown result counts, rich text): the skeleton would differ a lot, so use a simple spinner.
- Long tasks with exact progress, such as uploads and exports: use a progress bar or ring.
Usage
import { Skeleton, SkeletonSwap } from './Skeleton.jsx'
export function OrderCard({ order }) {
return (
<SkeletonSwap
loading={!order}
label="Loading order"
skeleton={
<div style={{ display: 'flex', gap: 12 }}>
<Skeleton variant="circle" height={40} />
<Skeleton lines={2} />
</div>
}
>
{order && <OrderDetail order={order} />}
</SkeletonSwap>
)
}Props
| Prop | Type | Default | What it does |
|---|---|---|---|
Skeleton.variant | 'line' | 'circle' | 'rect' | 'line' | Shape: text line, round avatar, or rectangle for an image or button. |
Skeleton.width | number | string | — | Width; numbers are px. line and rect default to 100%, circle to its height. |
Skeleton.height | number | string | — | Height; numbers are px. line defaults to 0.75em (follows font size), circle and rect to 40px. |
Skeleton.lines | number | 1 | Number of lines (line only). With more than one, the last line shortens to 60%. |
Skeleton.radius | number | string | — | Corner radius; defaults to a full pill for line, 10px for rect and a full circle for circle. |
Skeleton.duration | number | 1600 | Sweep period in ms. When omitted, follows the surrounding SkeletonSwap's shimmerDuration. |
Skeleton.animate | boolean | true | Sweeps the highlight. When false, only the static base colour stays. |
SkeletonSwap.loading | boolean | — | Whether it is loading. When it turns false, the skeleton fades out and the content fades in while rising. |
SkeletonSwap.skeleton | ReactNode | — | The skeleton shown while loading; match the real content's size as closely as you can. |
SkeletonSwap.children | ReactNode | — | The real content; not rendered while loading. |
SkeletonSwap.shimmerDuration | number | 1600 | Sweep period in ms for every Skeleton inside. |
SkeletonSwap.label | string | 'Loading' | Text announced to screen readers while loading. |
...rest | HTMLAttributes | — | Other attributes, such as className and style, go to the root element. |
Accessibility
- The container has aria-busy, so screen readers do not read half-loaded content during loading.
- A permanent role="status" region announces “Loading” when loading starts; set label for something more specific.
- All skeleton blocks are aria-hidden and never read as empty elements.
- With reduced motion there is no sweep, only the static base colour, and the swap replaces the content without movement.
Motion
The sweep cycle is 1600ms by default (70% sweeping, 30% pause), ease-in-out, in phase across blocks. The skeleton leaves in 200ms ease-in; content enters in 360ms ease-out after 60ms, rising 8px. In the demo the bars then rise for 900ms on cubic-bezier(0.22, 1, 0.36, 1), 30ms apart, while the total counts up. Reduced motion shows static blocks and swaps without movement.
Add it to your project
Copy the prompt into Codex or Claude Code. The agent reads the published source, shows you what it will write and adds the component next to your own.
Skeleton.jsxskeleton-shimmer.csstokens.cssREADME.md
Both files install together. The stylesheet reads the design tokens in tokens.css and carries fallbacks, so it also works alone.



