Skip to content
Atoms

Skeleton

Shimmering placeholders that keep the layout.

Installation

  1. Run the CLI

    Run pnpm dlx asta-ui@latest init once, then this. The file lands in components/astabyte/ and the colour tokens go into your CSS.

    $ pnpm dlx asta-ui@latest add skeleton

    Or with the shadcn CLI: pnpm dlx shadcn@latest add https://ui.astabyte.com/r/skeleton.json

  2. Or install the package

    Don’t want the file? Import from asta-ui/skeleton and update with pnpm update asta-ui. Add the stylesheet once. More.

    $ pnpm add asta-ui
    import { Skeleton } from "asta-ui/skeleton";
  3. Or copy it by hand

    Copy this file. Keep the paths, or fix the @/ imports. Then add the tokens from globals.css.

    "use client";
    
    import type { CSSProperties } from "react";
    
    const cx = (...c: (string | false | null | undefined)[]) => c.filter(Boolean).join(" ");
    
    const SHIMMER = `
    .kit-skel::after {
      content: ""; position: absolute; inset-block: 0; left: 0; width: 250%; pointer-events: none;
      background-image: linear-gradient(100deg, transparent 30%, color-mix(in srgb, var(--color-paper) 70%, transparent) 50%, transparent 70%);
      animation: kit-shimmer 1.6s cubic-bezier(.16,1,.3,1) infinite;
    }
    @keyframes kit-shimmer { from { transform: translateX(-90%) } to { transform: translateX(30%) } }
    @media (prefers-reduced-motion: reduce) { .kit-skel::after { animation: none !important } }
    `;
    // The sweep is a pseudo-element moved with transform (compositor only). Its 250% width and travel
    // match the old background-position sweep exactly: the highlight crosses from -100% to 200%.
    
    export interface SkeletonProps {
      /** `line` (text), `circle` (avatar) or `block` (image, card). */
      shape?: "line" | "circle" | "block";
      width?: CSSProperties["width"];
      height?: CSSProperties["height"];
      className?: string;
    }
    
    /** A placeholder with a soft light sweeping across it. Hidden from screen readers. */
    export function Skeleton({ shape = "line", width, height, className }: SkeletonProps) {
      return (
        <span
          aria-hidden
          className={cx(
            "kit-skel relative block overflow-hidden",
            shape === "line" && "h-3 rounded-full",
            shape === "circle" && "aspect-square shrink-0 self-start rounded-full",
            shape === "block" && "rounded-[10px]",
            className,
          )}
          style={{
            width,
            height: height ?? (shape === "circle" ? width : undefined),
            backgroundColor: "color-mix(in srgb, var(--color-ink) 7%, transparent)",
          }}
        >
          <style href="asta-skeleton" precedence="asta">{SHIMMER}</style>
        </span>
      );
    }
    
    /** Several lines of text; the last one is shorter, like a real paragraph. */
    export function SkeletonText({ lines = 3, className }: { lines?: number; className?: string }) {
      return (
        <span className={cx("flex flex-col gap-2", className)} aria-hidden>
          {Array.from({ length: lines }, (_, i) => (
            <Skeleton key={i} width={i === lines - 1 ? "62%" : "100%"} />
          ))}
        </span>
      );
    }
    
    /** A ready-made card placeholder: image, avatar, title and two lines. */
    export function SkeletonCard({ className }: { className?: string }) {
      return (
        <div role="status" aria-label="Loading" className={cx("flex w-full flex-col gap-4 rounded-xl bg-paper p-3 shadow-[inset_0_0_0_1px_color-mix(in_srgb,var(--color-ink)_10%,transparent)]", className)}>
          <Skeleton shape="block" className="aspect-[16/9] w-full" />
          <div className="flex items-center gap-3 px-1">
            <Skeleton shape="circle" width={36} />
            <div className="flex flex-1 flex-col gap-2">
              <Skeleton width="55%" />
              <Skeleton width="35%" className="!h-2.5" />
            </div>
          </div>
          <SkeletonText lines={2} className="px-1 pb-1" />
        </div>
      );
    }
    
    export default Skeleton;
    
  4. Or ask your AI agent

    Paste this into Claude Code, Cursor, Codex, v0 or Lovable. Fill in the last line. More in Prompts.

    Add the Astabyte UI Skeleton component to my project.
    
    Shimmering placeholders that keep the layout.
    It includes: line, circle, block, card.
    
    Install it:
    ```sh
    pnpm dlx asta-ui@latest add skeleton --radix
    ```
    Or with the shadcn CLI:
    ```sh
    pnpm dlx shadcn@latest add https://ui.astabyte.com/r/skeleton.json
    ```
    If the project isn't set up yet, run `pnpm dlx asta-ui@latest init --radix` first: it runs `shadcn init` when needed and adds the @astabyte registry (Next.js, Vite, React Router, Astro, TanStack Start; Tailwind CSS v4).
    
    Import it like this:
    ```tsx
    import { Button } from "@/components/astabyte/button";
    import { Skeleton, SkeletonCard, SkeletonText } from "@/components/astabyte/skeleton";
    ```
    
    Usage example and props: https://ui.astabyte.com/skeleton
    Full catalogue for context: https://ui.astabyte.com/llms.txt
    
    Rules:
    - Keep the colour tokens (paper, paper-2, ink, ink-2, mute, brand). Don't restyle with hard-coded colours; rebrand by changing the token values in the CSS.
    - Keep the motion as it is: transform and opacity only, and the prefers-reduced-motion fallback.
    - Keep keyboard, focus and ARIA behaviour.
    - Use fake data and fake brand names in examples.
    
    Use it to: [describe where it goes and what it should do]
  5. Or use plain HTML + CSS

    Not on React? Use it from Django, Rails, Laravel, Go html/template, htmx or a static page. Load asta.css and asta.js once (the head.html tab), then paste the markup. The ui.astabyte.com/cdn link is temporary: pin a version from jsDelivr for production. More in HTML + CSS.

    <div style="display:grid;gap:12px">
    <div class="asta-skeleton-card" role="status" aria-label="Loading" style="max-width:20rem"><span class="asta-skeleton asta-skeleton-block" aria-hidden="true"></span><div class="asta-skeleton-row"><span class="asta-skeleton asta-skeleton-circle" aria-hidden="true" style="width:36px;height:36px"></span><div class="asta-skeleton-stack"><span class="asta-skeleton" aria-hidden="true" style="width:55%"></span><span class="asta-skeleton" aria-hidden="true" style="width:35%;height:10px"></span></div></div><span class="asta-skeleton-text" aria-hidden="true"><span class="asta-skeleton"></span><span class="asta-skeleton"></span></span></div>
    </div>

Usage

The demo above, as code.

"use client";

import { useEffect, useState } from "react";
import { Button } from "@/components/astabyte/button";
import { Skeleton, SkeletonCard, SkeletonText } from "@/components/astabyte/skeleton";

function Loaded() {
  return (
    <div className="flex w-full animate-[kit-fade_.5s_cubic-bezier(.16,1,.3,1)] flex-col gap-4 rounded-xl bg-paper p-3 shadow-[inset_0_0_0_1px_color-mix(in_srgb,var(--color-ink)_10%,transparent)]">
      <style href="asta-demo-skeleton" precedence="asta">{`@keyframes kit-fade { from { opacity: 0; transform: translateY(4px) } }`}</style>
      <div className="flex aspect-[16/9] w-full items-end rounded-[10px] bg-brand p-4">
        <span className="text-[22px] font-medium leading-none tracking-[-0.03em] text-white">Field notes, vol. 3</span>
      </div>
      <div className="flex items-center gap-3 px-1">
        <span className="flex h-9 w-9 items-center justify-center rounded-full bg-ink text-[13px] font-medium text-paper">MP</span>
        <div className="flex flex-col">
          <span className="text-[14px] font-medium tracking-[-0.01em]">Maya Putri</span>
          <span className="text-[12px] text-mute">4 min read</span>
        </div>
      </div>
      <p className="px-1 pb-1 text-[13px] leading-relaxed text-ink-2">What we learned shipping motion to a payments flow, and the three animations we cut.</p>
    </div>
  );
}

export default function SkeletonDemo() {
  const [loading, setLoading] = useState(true);
  useEffect(() => {
    if (!loading) return;
    const t = setTimeout(() => setLoading(false), 2200);
    return () => clearTimeout(t);
  }, [loading]);

  return (
    <div className="flex min-h-[420px] w-full items-center justify-center p-6 sm:p-10">
      <div className="grid w-full max-w-xl items-start gap-6 sm:grid-cols-2">
        <div className="flex flex-col gap-3">
          <div aria-live="polite">{loading ? <SkeletonCard /> : <Loaded />}</div>
          <Button variant="soft" size="sm" onClick={() => setLoading(true)} disabled={loading} className="self-start">
            Reload
          </Button>
        </div>
        <div className="flex flex-col gap-6">
          <div className="flex flex-col gap-2">
            <span className="font-mono text-[11px] uppercase tracking-wider text-mute">Line</span>
            <SkeletonText lines={3} />
          </div>
          <div className="flex flex-col gap-2">
            <span className="font-mono text-[11px] uppercase tracking-wider text-mute">Circle</span>
            <div className="flex gap-2">
              <Skeleton shape="circle" width={28} />
              <Skeleton shape="circle" width={36} />
              <Skeleton shape="circle" width={44} />
            </div>
          </div>
          <div className="flex flex-col gap-2">
            <span className="font-mono text-[11px] uppercase tracking-wider text-mute">Block</span>
            <div className="grid grid-cols-3 gap-2">
              <Skeleton shape="block" className="aspect-square" />
              <Skeleton shape="block" className="aspect-square" />
              <Skeleton shape="block" className="aspect-square" />
            </div>
          </div>
        </div>
      </div>
    </div>
  );
}