# Skeleton

> Skeleton loader for React and shadcn: every placeholder on the page shares one shimmer, and the real content fades in in place.

Loading placeholders with one page-wide shimmer: every skeleton shares a highlight and a phase, so a single band sweeps across them all. Wrap the real content and it hands off in place, fading in from a soft blur.

Also known as a skeleton loader or a loading placeholder.

- Tier: Free (MIT)
- Interaction: Loading
- Page: https://eased.dev/components/skeleton
- Installs: motion
- Registry: https://eased.dev/r/skeleton.json

## Install

```bash
npx shadcn add https://eased.dev/r/skeleton.json
```

Loading placeholders with one page-wide shimmer, which hand off to the real content in place when it arrives.

## When to use

- Content loading into a layout you already know: a profile header, a list of rows, a card's text.
- Wrapping the real component while its data loads, so the placeholder is exactly its size and nothing shifts at the handoff.
- Several placeholders on one screen, which should shimmer as one band rather than each on its own beat.

## When not to use

- A wait with no layout to stand in for, or an action in progress: use a [Spinner](/components/spinner).
- A task with measurable progress: use [Progress](/components/progress).

## Usage

Wrap the real content and pass `loading`. While data is missing, render stand-in text of a typical length so the placeholder takes its size.

```tsx profile-header.tsx
import { Avatar } from "@/components/eased/avatar/avatar";
import { Skeleton } from "@/components/eased/skeleton/skeleton";

export function ProfileHeader({ user }: { user?: { name: string; role: string; photo: string } }) {
  return (
    <div className="flex items-center gap-3">
      <Skeleton loading={!user} className="rounded-pill">
        <Avatar name={user?.name ?? "Maya Okafor"} src={user?.photo} />
      </Skeleton>
      <div className="flex flex-col">
        <Skeleton loading={!user} text>
          <p className="text-ui font-medium">{user?.name ?? "Maya Okafor"}</p>
        </Skeleton>
        <Skeleton loading={!user} text>
          <p className="text-ui-sm text-text-muted">{user?.role ?? "Product designer"}</p>
        </Skeleton>
      </div>
    </div>
  );
}
```

## Examples

### Plain blocks

Without children a skeleton is a block; size and round it with classes.

```tsx
<Skeleton className="h-24 w-full rounded-panel" />
```

### Paragraph

`SkeletonText` draws lines sized for 13–14px text, the last one shorter.

```tsx
<SkeletonText lines={4} loading={!summary} />
```

## API reference

### Skeleton

| Prop | Type | Default | Description |
|---|---|---|---|
| `loading` | `boolean` | `true` | While true the shimmer shows; set it false to hand off to `children`. |
| `children` | `ReactNode` | | The real content, laid out invisibly and inert while loading. Without children the skeleton is a plain block. |
| `text` | `boolean` | `false` | Cover the middle 60% of each line box, so it reads as a line of text. |
| `block` | `boolean` | `false` | Lay the wrapper out as a block instead of inline, for cards and rows. |
| `className` | `string` | | Size and radius classes. Default radius `rounded-control-xs`; pass `rounded-pill` for avatars. |

### SkeletonText

| Prop | Type | Default | Description |
|---|---|---|---|
| `lines` | `number` | `3` | Number of lines; the last one is shorter. |
| `loading` | `boolean` | `true` | |
| `className` | `string` | `""` | |

## Accessibility

- A skeleton wrapping content sets `aria-busy` while loading, and the stand-in content is `inert`, so it cannot be focused, clicked or read until it arrives.
- The shimmer itself is hidden from assistive tech. Announce the loaded state yourself if it matters, for example in a live region.

## Motion

Every skeleton paints the same viewport-space highlight and every shimmer is pinned to the same start time, so a single band sweeps across the whole page every 2s instead of each block flashing on its own beat. When loading ends the shimmer fades out as the content fades in from a 4px blur in the same box. Reduced motion: a still tint, and an opacity handoff in 100ms.

The shared sweep has limits. The band is painted with `background-attachment: fixed`, which iOS Safari ignores, so there each skeleton sweeps its own box (still on the shared beat). Inside an ancestor that keeps a `transform` or `will-change` (an entrance animation that never resets), the background becomes relative to that element; end entrances with `transitionEnd: { transform: "none" }`. The loop does not pause off-screen: skeletons are short-lived.

## Notes for AI

Prefer wrapping the real component in Skeleton over drawing separate placeholder shapes: pass stand-in content of a typical length while data is missing (`user?.name ?? "Maya Okafor"`), and the placeholder will match the loaded layout exactly. Use `text` for text, a `rounded-*` class for avatars and media, and `block` when the wrapper should fill its row.

Do not swap between a skeleton tree and the loaded tree with a conditional: keep the same Skeleton mounted and flip `loading`, so the handoff animates in place. Do not add your own shimmer or pulse.

## Related

- [Spinner](/components/spinner): a wait with no layout to stand in for.
- [Progress](/components/progress): a task with measurable progress.
- [Avatar](/components/avatar): a picture to wrap while the person loads.

## Example

`components/eased/skeleton/skeleton-demo.tsx`

```tsx
"use client";

import { useEffect, useState } from "react";
import { Avatar } from "../avatar/avatar";
import { Button } from "../button/button";
import { DemoFrame } from "../lib/demo-frame";
import { Skeleton, SkeletonText } from "./skeleton";

type Activity = { id: string; who: string; did: string; what: string; when: string };

const FEED: Activity[] = [
  { id: "1", who: "Maya Okafor", did: "merged", what: "Checkout: smart address paste", when: "4m" },
  { id: "2", who: "Jonas Weber", did: "commented on", what: "Pricing page copy, v3", when: "18m" },
  { id: "3", who: "Priya Raman", did: "opened", what: "Skeleton flashes on fast networks", when: "1h" },
  { id: "4", who: "Leo Martín", did: "shipped", what: "Changelog 2.4", when: "3h" },
];

/** Simulates a request: 1.4s on the first load and on every reload. */
function useFeed() {
  const [attempt, setAttempt] = useState(0);
  const [data, setData] = useState<{ attempt: number; items: Activity[] } | null>(null);
  useEffect(() => {
    const t = window.setTimeout(() => setData({ attempt, items: FEED }), 1400);
    return () => window.clearTimeout(t);
  }, [attempt]);
  const loading = data?.attempt !== attempt;
  return { items: loading || !data ? null : data.items, loading, reload: () => setAttempt((a) => a + 1) };
}

export function SkeletonDemo() {
  const { items, loading, reload } = useFeed();

  return (
    <DemoFrame
      title="Activity"
      meta={loading ? "Loading…" : "Updated just now"}
      actions={
        <Button variant="ghost" size="sm" edge="end" onClick={reload} disabled={loading}>
          Reload
        </Button>
      }
    >
      <ul aria-busy={loading} className="flex flex-col p-1.5">
        {/* While loading, every row renders with stand-in text the length of a real one, so the handoff never moves a pixel. */}
        {(items ?? FEED).map((a) => (
          <li key={a.id} className="flex min-w-0 items-start gap-3 rounded-control px-2.5 py-3">
            <Skeleton loading={loading} className="size-8 shrink-0 rounded-pill">
              <Avatar name={a.who} size="md" />
            </Skeleton>
            <div className="flex min-w-0 flex-1 flex-col gap-1">
              <div className="flex min-w-0 items-baseline justify-between gap-3">
                <Skeleton loading={loading} text className="min-w-0">
                  <p className="truncate text-ui-sm text-text">
                    <span className="font-medium">{a.who}</span> <span className="text-text-secondary">{a.did}</span>
                  </p>
                </Skeleton>
                <Skeleton loading={loading} text className="shrink-0">
                  <span className="text-ui-xs text-text-muted tabular-nums">{a.when}</span>
                </Skeleton>
              </div>
              <Skeleton loading={loading} text className="min-w-0 self-start">
                <p className="truncate text-ui-sm text-text-secondary">{a.what}</p>
              </Skeleton>
            </div>
          </li>
        ))}
      </ul>

      <div className="mt-auto border-t border-line-subtle p-4">
        <p className="mb-2 text-ui-xs font-medium tracking-caps text-text-muted uppercase">Release notes</p>
        {/* The paragraph keeps its own box while loading and the lines overlay it, so the handoff never changes the height. */}
        <div aria-busy={loading} className="relative">
          <p
            className={`text-pretty text-ui-sm text-text-secondary ${
              loading
                ? "opacity-0"
                : "transition-opacity duration-(--eased-duration-standard) ease-enter reduced:duration-(--eased-duration-instant)"
            }`}
          >
            Skeletons now share one shimmer across the page, and hand off to content in place.
          </p>
          <SkeletonText lines={2} loading={loading} className="absolute inset-0 overflow-clip" />
        </div>
      </div>
    </DemoFrame>
  );
}
```
