# Skeleton

> Loading placeholder in line, circle or block shape with a shimmer, a pulse or no animation; stacked lines end with a shorter one.

- Kind: ui · Category: Feedback · Interactivity: none
- Install: `npx shadcn@latest add @haze/skeleton`
- File: `src/components/haze/ui/skeleton.astro`
- npm dependencies: none
- Registry dependencies: @haze/utils
- Docs page: https://hazeui.com/ui/skeleton

## Use 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 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
- [placeholder](https://hazeui.com/ui/placeholder.md)

## Props

| Name | Type | Default | Required | Description |
|---|---|---|---|---|
| variant | `"line" \| "circle" \| "block"` | "line" | no | Shape: text line, round avatar, or rectangular block. |
| lines | `number` | 1 | no | Number of text lines for the line variant; the last is two thirds wide. |
| animation | `"shimmer" \| "pulse" \| "none"` | "shimmer" | no | shimmer sweeps a highlight across the shape, pulse fades it in and out, none leaves it still. |
| class | `string` |  | no | 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.

## Agent prompts

### 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": "https://hazeui.com/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: https://hazeui.com/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.

## Example requests that should lead here
- Show a skeleton avatar with three text lines while the comment loads

## Source

```astro
---
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,
      )}
    />
  )
}
```
