Skeleton
A placeholder in the shape of content that is on its way: a block, lines of text, an avatar. It keeps the layout from jumping when the content arrives. Where the shape is not known, or the wait is short, use the spinner.
Install
npx shadcn@latest add https://thrumui.dev/r/skeleton.jsonAdds components/ui/skeleton.tsx. Nothing else in your project changes.
import { Skeleton } from "@/components/ui/skeleton";Props
| Prop | Type | Default | Description |
|---|---|---|---|
Skeleton | ComponentProps<"div"> | – | One block. It is 16 pixels tall and as wide as its container until className says otherwise: h-32, w-24, aspect-video. |
Skeleton: paused | boolean | Default false | Freeze the shimmer where it is. SkeletonText and SkeletonAvatar take the same prop. |
SkeletonText: lines | number | Default 3 | How many lines to draw: 12 pixel bars, 8 pixels apart. With two or more, the last one is 60% wide. |
SkeletonAvatar: square | boolean | Default false | Square with the corners of a control, in place of the round shape. |
SkeletonAvatar: className | string | – | Sets the size. It is 32 pixels without one; size-10 matches a large avatar. |
className | string | – | On every part: extra classes, merged last. |
...props | ComponentProps<"div"> | – | On every part: other div attributes are passed through. |
Motion and sound
Motion
- A soft band of the page colour, a little over half as wide as the block and fading at both edges, crosses each block from left to right. It starts again every 1.6 seconds.
- It is a CSS animation of the background position. The blocks themselves never move or change size.
- paused freezes the band where it is. A skeleton that starts paused shows no band.
- Reduced motion: no band. The blocks are flat and still.
Sound
Silent. This component makes no sound.
Accessibility
- Every block is hidden from screen readers with aria-hidden: a grey bar has nothing to say.
- Say that content is loading on the region instead: set aria-busy="true" on it while the skeleton shows, and remove it when the content is in.
- Match the size of the real content, so nothing shifts when it arrives.
- The blocks are the theme's muted colour. They are decoration and carry no information by colour.
Source
"use client";
import type { ComponentProps } from "react";
import { cn } from "@/lib/utils";
export type SkeletonProps = ComponentProps<"div"> & {
/** Freeze the shimmer where it is. */
paused?: boolean;
};
// A soft band of the page colour, 60% as wide as the block, crosses it from left to right. At rest it is parked outside the block.
const SHIMMER =
"bg-foreground/16 bg-[linear-gradient(100deg,transparent_38%,color-mix(in_srgb,var(--background)_85%,transparent)_50%,transparent_62%)] bg-[length:300%_100%] bg-[position:100%_0] bg-no-repeat " +
"animate-[skeleton-shimmer_1.6s_linear_infinite] motion-reduce:animate-none";
/** The classes of a skeleton block, without a shape. */
function shimmer(paused: boolean | undefined) {
return cn(SHIMMER, paused && "[animation-play-state:paused]");
}
/**
* A placeholder block for content that is still loading. Give it the size and shape of what will replace it with `className`.
* It is hidden from screen readers: put `aria-busy` on the region that is loading.
*/
export function Skeleton({ paused, className, ...props }: SkeletonProps) {
return <div data-slot="skeleton" aria-hidden="true" className={cn("h-4 w-full rounded-md", shimmer(paused), className)} {...props} />;
}
export type SkeletonTextProps = ComponentProps<"div"> & {
/** How many lines to draw. The last one is 60% wide, like the end of a paragraph. */
lines?: number;
/** Freeze the shimmer where it is. */
paused?: boolean;
};
/** Lines of text that are still loading: 12 pixel bars on a 20 pixel line. */
export function SkeletonText({ lines = 3, paused, className, ...props }: SkeletonTextProps) {
const count = Math.max(1, Math.floor(lines) || 1);
return (
<div data-slot="skeleton-text" aria-hidden="true" className={cn("flex w-full flex-col gap-2 py-1", className)} {...props}>
{Array.from({ length: count }, (_, i) => (
<div key={i} className={cn("h-3 rounded-sm", shimmer(paused), count > 1 && i === count - 1 ? "w-3/5" : "w-full")} />
))}
</div>
);
}
export type SkeletonAvatarProps = ComponentProps<"div"> & {
/** Square with the corners of a control, in place of the round shape. */
square?: boolean;
/** Freeze the shimmer where it is. */
paused?: boolean;
};
/** An avatar that is still loading: 32 pixels unless `className` sets another size. */
export function SkeletonAvatar({ square = false, paused, className, ...props }: SkeletonAvatarProps) {
return (
<div
data-slot="skeleton-avatar"
aria-hidden="true"
className={cn("size-8 shrink-0", square ? "rounded-md" : "rounded-[calc(var(--radius)*9999)]", shimmer(paused), className)}
{...props}
/>
);
}Files and dependencies
- Adds
components/ui/skeleton.tsx- Packages
- None
- Brings along
- Nothing
Changelog
- 1.0.0 · 2026-12-03First release.