← Components

Communication

Skeleton

Placeholders of known shape. Every skeleton shares one shimmer, so the page breathes together.

Examples and variants

Card placeholder

Shape it like the content.

Example
function SkeletonCard() {
  return (
    <div className="flex w-full max-w-xs flex-col gap-3" aria-busy="true">
      <Skeleton className="h-32 w-full rounded-(--shape-lg)" />
      <Skeleton className="h-3 w-2/3" />
      <Skeleton className="h-3 w-1/3" />
    </div>
  )
}

Spec drawing

Measured from the live component at default density. Each code maps to the token that sets it; change the token and the drawing follows.

Install

With the CLI

The shadcn CLI only delivers files: it copies our code from the Isotopi registry into your project and installs the packages it uses. Add the foundation once, then the component.

Terminal
npx shadcn@latest add https://isotopi.com/r/minimal.json
npx shadcn@latest add https://isotopi.com/r/skeleton.json

By hand

No CLI needed. Add the foundation once (see Getting started), then follow these steps. They include every component this one builds on.

  1. Install the packages it uses.

    Terminal
    npm install cn
  2. Copy this file to the same paths in your project. Imports use the @/ alias for your project root.

    • components/ui/skeleton.tsxskeleton
      components/ui/skeleton.tsx
      "use client"
      
      import * as React from "react"
      import { cn } from "cn"
      import { tokenMs } from "@/lib/motion/token-ms"
      
      /*
        Skeleton: a placeholder of known shape. Every skeleton on the page shares
        one shimmer position: the gradient is fixed to the viewport, and each
        skeleton's animation is offset to the page clock, so skeletons mounted at
        different times stay in step and the page breathes together.
      */
      function Skeleton({ className, ...props }: React.ComponentProps<"div">) {
        const ref = React.useRef<HTMLDivElement>(null)
      
        React.useEffect(() => {
          const node = ref.current
          if (!node) return
          const period = tokenMs("--duration-shimmer", node) || 1
          node.style.animationDelay = `-${performance.now() % period}ms`
        }, [])
      
        return (
          <div ref={ref} data-slot="skeleton" aria-hidden className={cn("skeleton rounded-(--skeleton-corner)", className)} {...props} />
        )
      }
      
      export { Skeleton }
      

Imports

What the examples on this page import:

Imports
import { Skeleton } from "@/components/ui/skeleton"

Anatomy

  1. 1Block · --skeleton-container, --skeleton-shine, --skeleton-corner.

Props

PropTypeDefaultDescription
classNamestring—Size and shape it like the content.

Tokens

Every visual spec is a component token in styles/tokens/components.css, pointing at a semantic token. Change a token to restyle the component; themes change the semantic layer.

TokenPoints toLightDark
--skeleton-containervar(--color-skeleton)oklch(0.965 0.005 95)oklch(0.22 0 0)
--skeleton-shinevar(--color-skeleton-shine)oklch(0.985 0.004 95)oklch(0.27 0 0)
--skeleton-cornervar(--shape-sm)8pxsame

Motion

TriggerWhat happensTokens
LoadingOne shared shimmer sweeps across all skeletons.--duration-shimmer

Calm keeps the motion without overshoot. Still (and reduced motion) keeps a designed frame with no movement.

Accessibility

  • Set aria-busy on the container.
  • Skeletons are hidden from screen readers.

Usage

Do

  • Match the real layout.

Don’t

  • Don't use for unknown shapes (use Loading indicator).

Code

components/ui/skeleton.tsx
"use client"

import * as React from "react"
import { cn } from "cn"
import { tokenMs } from "@/lib/motion/token-ms"

/*
  Skeleton: a placeholder of known shape. Every skeleton on the page shares
  one shimmer position: the gradient is fixed to the viewport, and each
  skeleton's animation is offset to the page clock, so skeletons mounted at
  different times stay in step and the page breathes together.
*/
function Skeleton({ className, ...props }: React.ComponentProps<"div">) {
  const ref = React.useRef<HTMLDivElement>(null)

  React.useEffect(() => {
    const node = ref.current
    if (!node) return
    const period = tokenMs("--duration-shimmer", node) || 1
    node.style.animationDelay = `-${performance.now() % period}ms`
  }, [])

  return (
    <div ref={ref} data-slot="skeleton" aria-hidden className={cn("skeleton rounded-(--skeleton-corner)", className)} {...props} />
  )
}

export { Skeleton }