Communication
Skeleton
Placeholders of known shape. Every skeleton shares one shimmer, so the page breathes together.
Examples and variants
Card placeholder
Shape it like the content.
function SkeletonCard() {
return (
<div className="flex w-full max-w-xs flex-col gap-3" aria-busy="true">
<Skeleton className="h-32 w-full rounded-(--shape-lg)" />
<Skeleton className="h-3 w-2/3" />
<Skeleton className="h-3 w-1/3" />
</div>
)
}Spec drawing
Measured from the live component at default density. Each code maps to the token that sets it; change the token and the drawing follows.
Install
With the CLI
The shadcn CLI only delivers files: it copies our code from the Isotopi registry into your project and installs the packages it uses. Add the foundation once, then the component.
npx shadcn@latest add https://isotopi.com/r/minimal.json
npx shadcn@latest add https://isotopi.com/r/skeleton.jsonBy hand
No CLI needed. Add the foundation once (see Getting started), then follow these steps. They include every component this one builds on.
Install the packages it uses.
Terminalnpm install cnCopy this file to the same paths in your project. Imports use the
@/alias for your project root.components/ui/skeleton.tsxskeleton
components/ui/skeleton.tsx"use client" import * as React from "react" import { cn } from "cn" import { tokenMs } from "@/lib/motion/token-ms" /* Skeleton: a placeholder of known shape. Every skeleton on the page shares one shimmer position: the gradient is fixed to the viewport, and each skeleton's animation is offset to the page clock, so skeletons mounted at different times stay in step and the page breathes together. */ function Skeleton({ className, ...props }: React.ComponentProps<"div">) { const ref = React.useRef<HTMLDivElement>(null) React.useEffect(() => { const node = ref.current if (!node) return const period = tokenMs("--duration-shimmer", node) || 1 node.style.animationDelay = `-${performance.now() % period}ms` }, []) return ( <div ref={ref} data-slot="skeleton" aria-hidden className={cn("skeleton rounded-(--skeleton-corner)", className)} {...props} /> ) } export { Skeleton }
Imports
What the examples on this page import:
import { Skeleton } from "@/components/ui/skeleton"Anatomy
- 1Block · --skeleton-container, --skeleton-shine, --skeleton-corner.
Props
| Prop | Type | Default | Description |
|---|---|---|---|
className | string | — | Size and shape it like the content. |
Tokens
Every visual spec is a component token in styles/tokens/components.css, pointing at a semantic token. Change a token to restyle the component; themes change the semantic layer.
| Token | Points to | Light | Dark |
|---|---|---|---|
--skeleton-container | var(--color-skeleton) | oklch(0.965 0.005 95) | oklch(0.22 0 0) |
--skeleton-shine | var(--color-skeleton-shine) | oklch(0.985 0.004 95) | oklch(0.27 0 0) |
--skeleton-corner | var(--shape-sm) | 8px | same |
Motion
| Trigger | What happens | Tokens |
|---|---|---|
| Loading | One shared shimmer sweeps across all skeletons. | --duration-shimmer |
Calm keeps the motion without overshoot. Still (and reduced motion) keeps a designed frame with no movement.
Accessibility
- Set aria-busy on the container.
- Skeletons are hidden from screen readers.
Usage
Do
- Match the real layout.
Don’t
- Don't use for unknown shapes (use Loading indicator).
Code
"use client"
import * as React from "react"
import { cn } from "cn"
import { tokenMs } from "@/lib/motion/token-ms"
/*
Skeleton: a placeholder of known shape. Every skeleton on the page shares
one shimmer position: the gradient is fixed to the viewport, and each
skeleton's animation is offset to the page clock, so skeletons mounted at
different times stay in step and the page breathes together.
*/
function Skeleton({ className, ...props }: React.ComponentProps<"div">) {
const ref = React.useRef<HTMLDivElement>(null)
React.useEffect(() => {
const node = ref.current
if (!node) return
const period = tokenMs("--duration-shimmer", node) || 1
node.style.animationDelay = `-${performance.now() % period}ms`
}, [])
return (
<div ref={ref} data-slot="skeleton" aria-hidden className={cn("skeleton rounded-(--skeleton-corner)", className)} {...props} />
)
}
export { Skeleton }