Skeleton
A loading placeholder in the control-outline tone.
Size and shape each skeleton with classes so it stands where the content will be: the content then arrives without moving the page. The pulse stops when the person prefers reduced motion; the shapes stay.
Shapes
import { Skeleton } from "@/components/ui/skeleton"
export default function SkeletonShapes() {
return (
<div className="flex w-full max-w-sm flex-col gap-6" aria-hidden>
<div className="flex flex-col gap-2">
<Skeleton className="h-4 w-3/4" />
<Skeleton className="h-4 w-full" />
<Skeleton className="h-4 w-1/2" />
</div>
<div className="flex items-center gap-3">
<Skeleton className="size-10 rounded-full" />
<Skeleton className="h-8 w-24 rounded-control" />
</div>
<Skeleton className="h-28 w-full rounded-xl" />
</div>
)
}
In place of content
Loading the project owner
"use client"
import { useState } from "react"
import { Avatar, AvatarFallback } from "@/components/ui/avatar"
import { Button } from "@/components/ui/button"
import { Skeleton } from "@/components/ui/skeleton"
export default function SkeletonInPlaceOfContent() {
const [loading, setLoading] = useState(true)
return (
<div className="flex w-full max-w-sm flex-col items-start gap-6">
<div className="flex h-10 w-full items-center gap-3" aria-busy={loading}>
{loading ? (
<>
<Skeleton className="size-10 rounded-full" />
<div className="flex flex-1 flex-col gap-2">
<Skeleton className="h-3.5 w-32" />
<Skeleton className="h-3 w-48" />
<span className="sr-only">Loading the project owner</span>
</div>
</>
) : (
<>
<Avatar size="lg" aria-hidden>
<AvatarFallback name="Ines Quill">IQ</AvatarFallback>
</Avatar>
<div className="flex flex-1 flex-col">
<span className="font-medium">Ines Quill</span>
<span className="text-sm text-muted-foreground">Owner of Atlas redesign</span>
</div>
</>
)}
</div>
<Button variant="outline" onClick={() => setLoading(!loading)}>
{loading ? "Show the content" : "Show the skeleton"}
</Button>
</div>
)
}
Installation
npx shadcn@latest add @khaeli/skeletonbunx --bun shadcn@latest add @khaeli/skeletonInstall @khaeli/foundation first: this item's styling lives in its tokens and [data-slot] rules.
Installs with
- Registry items
Accessible name
- A skeleton is an empty
divwith no role and no name: a screen reader finds nothing there. - Say what is loading in text, visually hidden if need be, and set
aria-busyon the region while it loads. A group of skeletons that is only decoration takesaria-hidden.
Registry JSON
The item as the shadcn CLI reads it, with every file it ships: https://ui.khaeli.com/r/skeleton.json