Skeleton
Loading placeholder in line, circle or block shape with a shimmer, a pulse or no animation; stacked lines end with a shorter one.
pnpm dlx shadcn@latest add @haze/skeleton---
import { cn } from "../../../lib/haze/utils";
interface Props {
variant?: "line" | "circle" | "block";
lines?: number;
/** shimmer: a soft highlight sweeps across. pulse: the shape fades in and out. none: a still shape. */
animation?: "shimmer" | "pulse" | "none";
class?: string;
}
const { variant = "line", lines = 1, animation = "shimmer", class: className } = Astro.props;
const animations = {
shimmer: "bg-linear-to-r from-muted via-border to-muted bg-[length:200%_100%] animate-shimmer",
pulse: "bg-muted animate-pulse",
none: "bg-muted",
};
const base = cn("rounded-lg motion-reduce:animate-none", animations[animation]);
const count = Math.max(1, Math.floor(lines));
const multi = variant === "line" && count > 1;
---
{
multi ? (
<div aria-hidden="true" class={cn("flex w-full flex-col gap-3", className)}>
{Array.from({ length: count }, (_, i) => (
<div class={cn(base, "h-3", i === count - 1 ? "w-2/3" : "w-full")} />
))}
</div>
) : (
<div
aria-hidden="true"
class={cn(
base,
variant === "circle" && "size-10 rounded-full",
variant === "block" && "h-24 w-full",
variant === "line" && "h-4 w-full",
className,
)}
/>
)
}When to use
- Reserving space for a card, list row or profile header while data loads
- Matching the final layout so the page does not jump when content arrives
- Showing a text paragraph shape with lines set to 3
When not to use
- The wait is a short action such as a button press; use a spinner or disabled state
- Loading failed; show an error message instead of a pulsing shape
Installation
Add the Haze registry to components.json once, then install Skeleton with the shadcn CLI. Works in any Astro project with Tailwind CSS v4.
pnpm dlx shadcn@latest add @haze/skeletonnpx shadcn@latest add @haze/skeletonyarn dlx shadcn@latest add @haze/skeletonbunx --bun shadcn@latest add @haze/skeletonFirst time? Registry and theme setup
1. Add to components.json:
{
"registries": {
"@haze": "http://localhost:4329/r/{name}.json"
}
}2. Install the theme once: npx shadcn@latest add @haze/theme, then import it after Tailwind in your global CSS:@import "./haze.css";
API reference
| Prop | Type | Default | Description |
|---|---|---|---|
| variant | "line" | "circle" | "block" | "line" | Shape: text line, round avatar, or rectangular block. |
| lines | number | 1 | Number of text lines for the line variant; the last is two thirds wide. |
| animation | "shimmer" | "pulse" | "none" | "shimmer" | shimmer sweeps a highlight across the shape, pulse fades it in and out, none leaves it still. |
| class | string | – | Sizing and spacing, for example h-6 w-40 or size-12. |
Accessibility
- With several lines, the last line is shorter so the block reads as a paragraph.
- Marked aria-hidden="true" because the shapes carry no information.
- Announce the loading state elsewhere, for example aria-busy="true" on the container or a visually hidden status text.
- The shimmer and the pulse are CSS animations; the theme's global reduced-motion rule stops them for users who ask for less motion.
Notes for AI
Copy into Claude Code, Cursor, Codex or any coding agent. Agents can also read the Markdown version of this page.
Install and use
Install the Haze UI component "Skeleton" with `npx shadcn@latest add @haze/skeleton`. If components.json has no "@haze" registry yet, add "registries": { "@haze": "http://localhost:4329/r/{name}.json" }. If src/styles/haze.css does not exist yet, run `npx shadcn@latest add @haze/theme` once and import it from the global stylesheet after Tailwind. The CLI stops at an overwrite question when a Haze file already exists and differs, even with --yes, and then installs nothing after it: read its output. If the user has not edited their Haze files, re-run with --overwrite to take the registry versions; if they have, ask them before overwriting. Then import Skeleton from "@/components/haze/ui/skeleton.astro" (or the relative path) and render it where it fits the page. Keep Haze token classes (bg-background, text-muted-foreground, border-border...) and never hardcode colors. Docs: http://localhost:4329/ui/skeleton.md
Customize with real content
Adapt the Haze skeleton ui for our product. Replace the demo values of these props with our real content: variant, lines, animation, class. Keep the layout, the heading level rules and these accessibility details: With several lines, the last line is shorter so the block reads as a paragraph. Marked aria-hidden="true" because the shapes carry no information. Announce the loading state elsewhere, for example aria-busy="true" on the container or a visually hidden status text. The shimmer and the pulse are CSS animations; the theme's global reduced-motion rule stops them for users who ask for less motion. Do not add raw color classes; use the Haze tokens.
Choose the right block
Before using skeleton, check it fits: use it when reserving space for a card, list row or profile header while data loads; matching the final layout so the page does not jump when content arrives; showing a text paragraph shape with lines set to 3. Avoid it when the wait is a short action such as a button press; use a spinner or disabled state; loading failed; show an error message instead of a pulsing shape. Alternatives: @haze/placeholder.
Dependencies
- @haze/utils
- @haze/theme (one-time setup)
Source · Original Haze UI work.