Skeleton
The shadcn/ui Skeleton with a soft shimmer sweep tuned for dark UIs and a static fallback for reduced motion — plus React skeleton loader blocks: ready-made text, avatar, card and table placeholders with a wave-like shimmer, and a content loader that crossfades from skeleton to content while animating its height.
- Drop-in shadcn API
- Server Component
- CSS shimmer
- prefers-reduced-motion
Comments
"use client";
import * as React from "react";
import { MessageSquare, RotateCw } from "lucide-react";
import { Button } from "@/components/ui/button";
import { ContentLoader } from "@/components/dusk/skeleton/content-loader";
import { SkeletonAvatarRow, SkeletonText } from "@/components/dusk/skeleton/skeleton-presets";
const comments = [
{ initials: "AK", name: "Ada Kim", time: "2m", text: "The new spring on the drawer feels so much better. Shipping it?" },
{ initials: "LP", name: "Leo Park", time: "9m", text: "Yes, after the reduced-motion pass." },
{
initials: "ID",
name: "Ines Duarte",
time: "1h",
text: "Left two notes on the focus order in the dialog. Otherwise looks great, nice work on the height animation.",
},
];
export default function ContentLoaderDemo() {
const [loading, setLoading] = React.useState(true);
const timer = React.useRef<ReturnType<typeof setTimeout>>(undefined);
const load = React.useCallback(() => {
setLoading(true);
clearTimeout(timer.current);
timer.current = setTimeout(() => setLoading(false), 1800);
}, []);
React.useEffect(() => {
timer.current = setTimeout(() => setLoading(false), 1800);
return () => clearTimeout(timer.current);
}, []);
return (
<div className="flex w-full max-w-md flex-col items-center gap-4">
<section className="w-full rounded-xl border bg-card p-4" aria-labelledby="comments-heading">
<h3 id="comments-heading" className="mb-4 flex items-center gap-2 text-sm font-medium">
<MessageSquare className="size-4 text-muted-foreground" aria-hidden />
Comments
</h3>
<ContentLoader
loading={loading}
loadingLabel="Loading comments"
stagger
contentClassName="grid gap-5"
skeleton={
<div className="grid gap-5">
<div className="grid gap-3">
<SkeletonAvatarRow avatarClassName="size-8" />
<SkeletonText lines={2} className="pl-11" />
</div>
<div className="grid gap-3">
<SkeletonAvatarRow avatarClassName="size-8" />
<SkeletonText lines={1} className="pl-11" lastLineClassName="w-1/2" />
</div>
</div>
}
>
{comments.map((comment) => (
<article key={comment.name} className="flex gap-3">
<span
aria-hidden
className="grid size-8 shrink-0 place-items-center rounded-full bg-muted text-xs font-medium text-muted-foreground"
>
{comment.initials}
</span>
<div className="grid gap-1">
<p className="text-sm">
<span className="font-medium">{comment.name}</span>{" "}
<span className="text-muted-foreground">· {comment.time}</span>
</p>
<p className="text-sm leading-relaxed text-muted-foreground">{comment.text}</p>
</div>
</article>
))}
</ContentLoader>
</section>
<Button variant="ghost" size="sm" onClick={load} aria-disabled={loading || undefined} className="aria-disabled:opacity-50">
<RotateCw />
Reload
</Button>
</div>
);
}Installation
$ npx shadcn@latest add https://duskui.com/r/skeleton.json1. Copy the source into
components/ui/skeleton.tsx.skeleton.tsx import * as React from "react"; import { cn } from "@/lib/utils"; export interface SkeletonProps extends React.ComponentProps<"div"> { /** * `shimmer` (default) sweeps a soft light across the block, `pulse` fades it * like shadcn, `none` is static. All become static under reduced motion. */ animation?: "shimmer" | "pulse" | "none"; } /** * DuskUI Skeleton — a drop-in upgrade of the shadcn/ui Skeleton. * * Same API as shadcn (size and shape it with classes) plus: * - A shimmer sweep instead of a pulse, tuned for dark surfaces. * - `animation`: "shimmer" | "pulse" | "none". * - Under `prefers-reduced-motion` it is static: no sweep and no pulse. * CSS only (tw-animate-css keyframes), so it works in Server Components and * renders identically on the server and client. */ function Skeleton({ className, animation = "shimmer", children, ...props }: SkeletonProps) { return ( <div data-slot="skeleton" data-animation={animation} className={cn( "relative isolate overflow-hidden rounded-md bg-accent/60", animation === "pulse" && "animate-pulse motion-reduce:animate-none", className )} {...props} > {animation === "shimmer" && ( // Starts one width to the left of the block and travels one width past // its right edge, so every sweep fully enters and leaves. <span aria-hidden data-slot="skeleton-shimmer" className={cn( "pointer-events-none absolute inset-y-0 left-full -z-10 w-full", "bg-linear-to-r from-transparent via-white/[0.07] to-transparent", "animate-in slide-in-from-left-[200%] repeat-infinite animation-duration-[1.8s] ease-in-out", "motion-reduce:hidden" )} /> )} {children} </div> ); } export { Skeleton };
Replaces components/ui/skeleton.tsx with the same Skeleton export, so the Sidebar's menu skeleton and your existing placeholders keep working. The shimmer is pure CSS (tw-animate-css keyframes, included with shadcn/ui): no JavaScript, works in Server Components and renders the same on server and client.
Usage
import { Skeleton } from "@/components/ui/skeleton"
export function ProfileSkeleton() {
return (
<div className="flex items-center gap-4" role="status">
<span className="sr-only">Loading profile</span>
<Skeleton className="size-12 rounded-full" />
<div className="grid gap-2">
<Skeleton className="h-4 w-48" />
<Skeleton className="h-4 w-32" />
</div>
</div>
)
}Examples
Default
Size and shape each block with classes, exactly like shadcn/ui. A faint light sweeps across every block instead of the whole thing pulsing.
import { Skeleton } from "@/components/ui/skeleton";
export default function SkeletonBasicDemo() {
return (
<div className="flex w-full max-w-sm items-center gap-4" role="status">
<span className="sr-only">Loading profile</span>
<Skeleton className="size-12 shrink-0 rounded-full" />
<div className="grid flex-1 gap-2">
<Skeleton className="h-4 w-3/4" />
<Skeleton className="h-4 w-1/2" />
</div>
</div>
);
}Animation
animation picks "shimmer" (default), shadcn's "pulse", or "none". With prefers-reduced-motion, all three are static.
import { Skeleton } from "@/components/ui/skeleton";
const modes = [
{ animation: "shimmer", label: "shimmer (default)" },
{ animation: "pulse", label: "pulse" },
{ animation: "none", label: "none" },
] as const;
export default function SkeletonAnimationsDemo() {
return (
<div className="grid w-full max-w-2xl gap-6 sm:grid-cols-3">
{modes.map(({ animation, label }) => (
<figure key={animation} className="grid gap-3">
<div className="grid gap-2 rounded-xl border bg-card p-4" aria-hidden>
<Skeleton animation={animation} className="aspect-video w-full rounded-lg" />
<Skeleton animation={animation} className="h-3.5 w-3/4" />
<Skeleton animation={animation} className="h-3 w-1/2" />
</div>
<figcaption className="text-center font-mono text-xs text-muted-foreground">{label}</figcaption>
</figure>
))}
</div>
);
}Blocks
Ready-made variations composed from the base component with Motion. Each installs on its own and pulls in its dependencies automatically.
Skeleton Presets
SkeletonText, SkeletonAvatarRow, SkeletonCard and SkeletonTable: common layouts in one line. Line widths follow a fixed rhythm (never random, so hydration is safe) and each block's shimmer starts a beat after the previous one, so the light rolls through the layout as a wave. Server Components, no Motion needed.
import {
SkeletonAvatarRow,
SkeletonCard,
SkeletonTable,
SkeletonText,
} from "@/components/dusk/skeleton/skeleton-presets";
export default function SkeletonPresetsDemo() {
return (
<div className="grid w-full max-w-2xl gap-6" role="status" aria-label="Loading dashboard">
<div className="grid gap-6 sm:grid-cols-2">
<SkeletonCard />
<div className="grid content-start gap-6 rounded-xl border bg-card p-4">
<SkeletonAvatarRow action />
<SkeletonText lines={4} />
<SkeletonAvatarRow square avatarClassName="size-9" />
</div>
</div>
<SkeletonTable rows={4} columns={4} />
</div>
);
}$ npx shadcn@latest add https://duskui.com/r/skeleton-presets.json1. Copy the source into
components/dusk/skeleton/skeleton-presets.tsx.skeleton-presets.tsx import * as React from "react"; import { Skeleton } from "@/components/ui/skeleton"; import { cn } from "@/lib/utils"; /* * Ready-made placeholders built from the DuskUI Skeleton. Each one is a * Server Component, uses fixed (not random) widths so server and client * HTML match, and staggers its shimmer so the light rolls through the * layout as a wave instead of flashing everything at once. * * They are hidden from screen readers by default. Pass `label` to turn the * preset into a polite role="status" region that announces it, or set * `aria-busy` on the region you are loading instead. */ // Static class strings so Tailwind can see them. Delays the shimmer of the nth block. const wave = [ "", "*:data-[slot=skeleton-shimmer]:[animation-delay:90ms]", "*:data-[slot=skeleton-shimmer]:[animation-delay:180ms]", "*:data-[slot=skeleton-shimmer]:[animation-delay:270ms]", "*:data-[slot=skeleton-shimmer]:[animation-delay:360ms]", "*:data-[slot=skeleton-shimmer]:[animation-delay:450ms]", "*:data-[slot=skeleton-shimmer]:[animation-delay:540ms]", "*:data-[slot=skeleton-shimmer]:[animation-delay:630ms]", ]; const waveAt = (index: number) => wave[Math.min(index, wave.length - 1)]; // A natural-looking rhythm of line lengths, repeated. const lineWidths = ["w-full", "w-11/12", "w-full", "w-4/5", "w-10/12", "w-full"]; interface PresetProps extends React.ComponentProps<"div"> { /** Announce this placeholder to screen readers, e.g. "Loading comments". */ label?: string; } function PresetRoot({ label, className, children, ...props }: PresetProps) { return ( <div role={label ? "status" : undefined} aria-hidden={label ? undefined : true} className={className} {...props} > {label && <span className="sr-only">{label}</span>} {children} </div> ); } export interface SkeletonTextProps extends PresetProps { /** Number of lines. */ lines?: number; /** Width of the last line, as a Tailwind class. */ lastLineClassName?: string; /** Classes for every line, e.g. a different height. */ lineClassName?: string; } /** A paragraph of text lines with a shorter last line. */ export function SkeletonText({ lines = 3, lastLineClassName = "w-3/5", lineClassName, className, ...props }: SkeletonTextProps) { return ( <PresetRoot className={cn("grid gap-2.5", className)} {...props}> {Array.from({ length: lines }, (_, i) => ( <Skeleton key={i} className={cn( "h-3", i === lines - 1 && lines > 1 ? lastLineClassName : lineWidths[i % lineWidths.length], waveAt(i), lineClassName )} /> ))} </PresetRoot> ); } export interface SkeletonAvatarRowProps extends PresetProps { /** Avatar diameter, as a Tailwind size class. */ avatarClassName?: string; /** Square avatar with rounded corners instead of a circle. */ square?: boolean; /** Show a trailing button placeholder. */ action?: boolean; } /** An avatar with a name and a subtitle, like a list item or comment header. */ export function SkeletonAvatarRow({ avatarClassName = "size-10", square = false, action = false, className, ...props }: SkeletonAvatarRowProps) { return ( <PresetRoot className={cn("flex items-center gap-3", className)} {...props}> <Skeleton className={cn("shrink-0", square ? "rounded-lg" : "rounded-full", avatarClassName)} /> <div className="grid flex-1 gap-2"> <Skeleton className={cn("h-3.5 w-2/5", waveAt(1))} /> <Skeleton className={cn("h-3 w-1/4", waveAt(2))} /> </div> {action && <Skeleton className={cn("h-8 w-20 shrink-0", waveAt(3))} />} </PresetRoot> ); } export interface SkeletonCardProps extends PresetProps { /** Show an image area on top. */ media?: boolean; /** Number of description lines. */ lines?: number; /** Show the footer row (avatar + button). */ footer?: boolean; } /** A content card: optional media, a title, a few lines and a footer. */ export function SkeletonCard({ media = true, lines = 2, footer = true, className, ...props }: SkeletonCardProps) { return ( <PresetRoot className={cn("grid gap-4 overflow-hidden rounded-xl border bg-card p-4", className)} {...props} > {media && <Skeleton className="aspect-video w-full rounded-lg" />} <div className="grid gap-2.5"> <Skeleton className={cn("h-4 w-3/5", waveAt(1))} /> {Array.from({ length: lines }, (_, i) => ( <Skeleton key={i} className={cn("h-3", i === lines - 1 && lines > 1 ? "w-4/5" : "w-full", waveAt(i + 2))} /> ))} </div> {footer && ( <div className="flex items-center gap-2 pt-1"> <Skeleton className={cn("size-7 rounded-full", waveAt(lines + 2))} /> <Skeleton className={cn("h-3 w-24", waveAt(lines + 2))} /> <Skeleton className={cn("ml-auto h-8 w-20", waveAt(lines + 3))} /> </div> )} </PresetRoot> ); } export interface SkeletonTableProps extends PresetProps { rows?: number; columns?: number; /** Show the header row. */ header?: boolean; } // Column widths cycle so the table doesn't look like a grid of identical bars. const cellWidths = ["w-3/4", "w-1/2", "w-2/3", "w-2/5", "w-1/3"]; /** A data table: header row plus body rows, with a leading avatar column. */ export function SkeletonTable({ rows = 5, columns = 4, header = true, className, ...props }: SkeletonTableProps) { const grid = { gridTemplateColumns: `minmax(0,1.6fr) repeat(${Math.max(columns - 1, 0)}, minmax(0,1fr))` }; return ( <PresetRoot className={cn("overflow-hidden rounded-xl border", className)} {...props}> {header && ( <div className="grid items-center gap-4 border-b bg-muted/40 px-4 py-3" style={grid}> {Array.from({ length: columns }, (_, c) => ( <Skeleton key={c} animation="none" className={cn("h-2.5 bg-accent/50", c === 0 ? "w-16" : "w-12")} /> ))} </div> )} <div className="divide-y"> {Array.from({ length: rows }, (_, r) => ( <div key={r} className="grid items-center gap-4 px-4 py-3" style={grid}> {Array.from({ length: columns }, (_, c) => c === 0 ? ( <div key={c} className="flex items-center gap-3"> <Skeleton className={cn("size-7 shrink-0 rounded-full", waveAt(r))} /> <Skeleton className={cn("h-3", cellWidths[r % cellWidths.length], waveAt(r))} /> </div> ) : ( <Skeleton key={c} className={cn("h-3", cellWidths[(r + c) % cellWidths.length], waveAt(r))} /> ) )} </div> ))} </div> </PresetRoot> ); }
| Prop | Type | Default | Description |
|---|---|---|---|
| label | string | — | All presets. Announce it as a polite role="status" region. Hidden from screen readers when omitted. |
| lines | number | 3 (Text) / 2 (Card) | SkeletonText, SkeletonCard: number of text lines. |
| lastLineClassName / lineClassName | string | "w-3/5" | SkeletonText: width of the last line / classes for every line. |
| avatarClassName / square / action | string / boolean / boolean | "size-10" / false / false | SkeletonAvatarRow: avatar size, rounded-square avatar, trailing button. |
| media / footer | boolean | true | SkeletonCard: image area and footer row. |
| rows / columns / header | number / number / boolean | 5 / 4 / true | SkeletonTable: body rows, columns and header row. |
Content Loader
Swaps a skeleton for the real content. The two crossfade while the wrapper's height springs from one to the other, so whatever sits below glides instead of jumping. With stagger, the content's children rise in one after another. The region is aria-busy while loading and announces loadingLabel. Press Reload.
Comments
"use client";
import * as React from "react";
import { MessageSquare, RotateCw } from "lucide-react";
import { Button } from "@/components/ui/button";
import { ContentLoader } from "@/components/dusk/skeleton/content-loader";
import { SkeletonAvatarRow, SkeletonText } from "@/components/dusk/skeleton/skeleton-presets";
const comments = [
{ initials: "AK", name: "Ada Kim", time: "2m", text: "The new spring on the drawer feels so much better. Shipping it?" },
{ initials: "LP", name: "Leo Park", time: "9m", text: "Yes, after the reduced-motion pass." },
{
initials: "ID",
name: "Ines Duarte",
time: "1h",
text: "Left two notes on the focus order in the dialog. Otherwise looks great, nice work on the height animation.",
},
];
export default function ContentLoaderDemo() {
const [loading, setLoading] = React.useState(true);
const timer = React.useRef<ReturnType<typeof setTimeout>>(undefined);
const load = React.useCallback(() => {
setLoading(true);
clearTimeout(timer.current);
timer.current = setTimeout(() => setLoading(false), 1800);
}, []);
React.useEffect(() => {
timer.current = setTimeout(() => setLoading(false), 1800);
return () => clearTimeout(timer.current);
}, []);
return (
<div className="flex w-full max-w-md flex-col items-center gap-4">
<section className="w-full rounded-xl border bg-card p-4" aria-labelledby="comments-heading">
<h3 id="comments-heading" className="mb-4 flex items-center gap-2 text-sm font-medium">
<MessageSquare className="size-4 text-muted-foreground" aria-hidden />
Comments
</h3>
<ContentLoader
loading={loading}
loadingLabel="Loading comments"
stagger
contentClassName="grid gap-5"
skeleton={
<div className="grid gap-5">
<div className="grid gap-3">
<SkeletonAvatarRow avatarClassName="size-8" />
<SkeletonText lines={2} className="pl-11" />
</div>
<div className="grid gap-3">
<SkeletonAvatarRow avatarClassName="size-8" />
<SkeletonText lines={1} className="pl-11" lastLineClassName="w-1/2" />
</div>
</div>
}
>
{comments.map((comment) => (
<article key={comment.name} className="flex gap-3">
<span
aria-hidden
className="grid size-8 shrink-0 place-items-center rounded-full bg-muted text-xs font-medium text-muted-foreground"
>
{comment.initials}
</span>
<div className="grid gap-1">
<p className="text-sm">
<span className="font-medium">{comment.name}</span>{" "}
<span className="text-muted-foreground">· {comment.time}</span>
</p>
<p className="text-sm leading-relaxed text-muted-foreground">{comment.text}</p>
</div>
</article>
))}
</ContentLoader>
</section>
<Button variant="ghost" size="sm" onClick={load} aria-disabled={loading || undefined} className="aria-disabled:opacity-50">
<RotateCw />
Reload
</Button>
</div>
);
}$ npx shadcn@latest add https://duskui.com/r/content-loader.json1. Install the dependencies.
npm install motion2. Copy the source into
components/dusk/skeleton/content-loader.tsx.content-loader.tsx "use client"; import * as React from "react"; import { AnimatePresence, motion, useReducedMotion } from "motion/react"; import { cn } from "@/lib/utils"; export interface ContentLoaderProps extends Omit<React.ComponentProps<"div">, "onAnimationStart" | "onDrag" | "onDragStart" | "onDragEnd"> { /** Show `skeleton` instead of `children`. */ loading: boolean; /** The placeholder. Build it from Skeleton or the skeleton presets, shaped like the content. */ skeleton: React.ReactNode; /** Announced to screen readers while loading. */ loadingLabel?: string; /** Announced once the content is in. Leave empty to stay quiet. */ loadedLabel?: string; /** Fade the direct children of the content in one after another. */ stagger?: boolean; /** Classes for the element that wraps `children`, e.g. "grid gap-4". */ contentClassName?: string; } const swap = { type: "spring", duration: 0.3, bounce: 0 } as const; /** Tracks an element's height so the wrapper can spring between skeleton and content sizes. */ function useMeasuredHeight<T extends HTMLElement>() { const ref = React.useRef<T>(null); const [height, setHeight] = React.useState<number>(); React.useLayoutEffect(() => { const el = ref.current; if (!el) return; const observer = new ResizeObserver(([entry]) => setHeight(entry.borderBoxSize?.[0]?.blockSize ?? el.offsetHeight) ); observer.observe(el); return () => observer.disconnect(); }, []); return [ref, height] as const; } /** * Swaps a skeleton for the real content. The two crossfade * while the wrapper's height springs from one to the other, so whatever sits * below glides instead of jumping. With `stagger`, the content's direct * children fade up one after another. The region is aria-busy while loading * and announces `loadingLabel` politely. Under reduced motion the height * snaps and only the opacity fades. */ export function ContentLoader({ loading, skeleton, loadingLabel = "Loading", loadedLabel = "", stagger = false, contentClassName, className, children, ...props }: ContentLoaderProps) { const reduceMotion = useReducedMotion(); const [measureRef, height] = useMeasuredHeight<HTMLDivElement>(); return ( <div data-slot="content-loader" aria-busy={loading || undefined} className={cn("relative", className)} {...props} > <span className="sr-only" aria-live="polite"> {loading ? loadingLabel : loadedLabel} </span> <motion.div className="overflow-hidden" initial={false} animate={{ height: height ?? "auto" }} transition={reduceMotion ? { duration: 0 } : swap} > <div ref={measureRef} className="relative"> <AnimatePresence mode="popLayout" initial={false}> <motion.div key={loading ? "skeleton" : "content"} aria-hidden={loading || undefined} className={loading ? undefined : contentClassName} initial={{ opacity: 0 }} animate={{ opacity: 1 }} exit={{ opacity: 0 }} transition={swap} > {loading || !stagger ? ( loading ? skeleton : children ) : ( <motion.div className="contents" initial="hidden" animate="visible" variants={{ visible: { transition: { staggerChildren: 0.04, delayChildren: 0.03 } } }} > {React.Children.map(children, (child) => child == null || typeof child === "boolean" ? child : ( <motion.div variants={{ hidden: { opacity: 0, y: reduceMotion ? 0 : 4 }, visible: { opacity: 1, y: 0, transition: swap }, }} > {child} </motion.div> ) )} </motion.div> )} </motion.div> </AnimatePresence> </div> </motion.div> </div> ); }
| Prop | Type | Default | Description |
|---|---|---|---|
| loading | boolean | — | Show the skeleton instead of the children. Required. |
| skeleton | ReactNode | — | The placeholder, shaped like the content. Required. |
| children | ReactNode | — | The loaded content. |
| stagger | boolean | false | Fade the children in one after another. |
| contentClassName | string | — | Classes for the element wrapping the children, e.g. "grid gap-4". |
| loadingLabel / loadedLabel | string | "Loading" / "" | Screen-reader announcements. |
API Reference
Skeleton renders a div and forwards all its props. Size and shape it with classes.
| Prop | Type | Default | Description |
|---|---|---|---|
| animation | "shimmer" | "pulse" | "none" | "shimmer" | The loading effect. Static under reduced motion. |
| className | string | — | Size and shape, e.g. h-4 w-48 or size-10 rounded-full. |
Accessibility
- Skeleton blocks are decorative. Mark the region you are loading with
aria-busyor arole="status"with a visually hidden label (Content Loader and the presets'labeldo this for you). - Shape placeholders like the real content so the page doesn't shift when it arrives; Content Loader animates any remaining height difference.
- Under prefers-reduced-motion the shimmer and pulse stop entirely, and Content Loader snaps its height and only fades.