Skeleton
Holds the place of content that is still loading, in the shape it will take.
Installation
pnpm dlx shadcn@latest add @silkware/skeletonTo copy the component by hand, install its dependency:
pnpm add cnThen copy the source into components/ui/skeleton.tsx:
import { cn } from "cn"
function Skeleton({ className, ...props }: React.ComponentProps<"div">) { return ( <div data-slot="skeleton" className={cn("animate-pulse rounded-md bg-muted", className)} {...props} /> )}
export { Skeleton }Usage
import { Skeleton } from "@/components/ui/skeleton"<Skeleton className="h-4 w-48" />A Skeleton has no size of its own. Give it the height and width of the content it replaces, and a radius to match: rounded-full for an avatar. It pulses with the animate-pulse utility and uses the muted colour. The global reduced-motion rule of the theme stops the pulse for people who ask for less motion.
Examples
Avatar and text
The first example on this page. Match the shapes of the real content: a circle where the avatar will be and bars where the lines will be.
Card
Keep the real header and card, and replace only the content that is loading.
Text
Stack bars of full width and end with a shorter one, as a paragraph does.
Table
Repeat a row of bars for the rows you expect. Give the group role="status" and an aria-label, so screen readers know something is loading.
Accessibility
| Key | Action |
|---|---|
| Tab | Does nothing. A skeleton is not focusable. |
React Aria provides nothing here: the skeleton is a styled div.
You provide:
- A status for the loading area:
role="status"with anaria-labelsuch as "Loading purchase orders", oraria-busy="true"on the region that is loading. - The same label once for the area, not once per bar.
- A swap to the real content that keeps focus where it was.
Guidelines
When to use
- For content whose shape you know: a card, a list, a table, a line of text.
- For loads that take more than a moment, where a blank area would look broken.
When not to use
- For an action in progress, such as saving or sending. Use a Spinner in the Button.
- For a measured process with a known length. Use Progress.
- For content whose shape you cannot predict. Use a Spinner with a label.
- When loading has finished and there is nothing to show. Use Empty.
- For loads under a few hundred milliseconds. Show nothing and then the content: a flash of grey is worse than a short wait.
Content
- A skeleton holds no text. Do not write labels on the bars.
- Match the count and size of the real content: four rows for four rows, not ten for four.
- Keep static parts real. Titles and buttons that do not depend on the data stay as they are.
- Name the loading area once, in words.
Shape
Mirror the layout of the content: a circle and two lines of text.
Don’t use one big block. The page jumps when the real layout arrives.
API reference
Skeleton
Renders a div with the pulse animation, a 6px radius and the muted background. It accepts every div prop.
| Prop | Type | Default | Description |
|---|---|---|---|
className? | string | None | Classes that set the size and the shape, merged after the base classes. |