Skip to main content

Skeleton

Show a placeholder while content is loading.

Props
Slots

Anatomy#

Skeleton [component; slot=root; <div>]

Usage#

Use Skeleton to reserve space for content while it loads. Match the placeholder’s dimensions and shape to the content it will replace. For measurable task completion, use Progress.

import { Skeleton } from 'moraine'

export function Example() {
  return (
    <div class="flex gap-4 max-w-sm w-full items-center">
      <Skeleton class="rounded-full shrink-0 size-12" />
      <div class="flex-1 min-w-0 space-y-2">
        <Skeleton class="h-4 max-w-[250px] w-full" />
        <Skeleton class="h-4 max-w-[200px] w-full" />
      </div>
    </div>
  )
}

Size and appearance#

Skeleton renders one <div> with a muted background, medium corners, and a pulse animation. Set its dimensions with class or an object style, and use utilities such as rounded-full to change its shape. Native div attributes and children go to the root. Skeleton adds no ARIA attributes or roles, so add them to the surrounding region when assistive technology needs a loading state.

<Skeleton class="rounded-full size-10" />
<Skeleton class="h-4 w-2/3" />

Animation variants#

The default variant="pulse" fades the placeholder in and out. Use variant="shimmer" for a linear gradient sweep across the placeholder. Both animations respect the user’s reduced-motion preference.

Shimmer uses Moraine’s loop duration, which defaults to two seconds. Set --mo-anim-duration-loop or --mo-anim-duration in style to change its speed; --mo-anim-duration takes precedence. Configure skeleton.defaultVariants.variant in your Theme to set the default animation across your application.

<Skeleton variant="shimmer" class="h-4 w-full" />
<Skeleton variant="shimmer" class="h-4 w-full" style={{ '--mo-anim-duration-loop': '1s' }} />

Examples#

Reserve a profile row#

Match a circular avatar and two text lines so the loaded row does not shift.

import { Skeleton } from 'moraine'

export function SkeletonAvatar() {
  return (
    <div class="flex gap-4 w-fit items-center">
      <Skeleton class="rounded-full shrink-0 size-10" />
      <div class="gap-2 grid">
        <Skeleton class="h-4 w-[150px]" />
        <Skeleton class="h-4 w-[100px]" />
      </div>
    </div>
  )
}

Placeholder a media card#

Keep Card anatomy and replace title, description, and media with Skeleton.

import { Card, Skeleton } from 'moraine'

export function SkeletonCard() {
  return (
    <Card class="max-w-xs w-full">
      <Card.Header>
        <div class="flex flex-col gap-2">
          <Skeleton class="h-4 w-2/3" />
          <Skeleton class="h-4 w-1/2" />
        </div>
      </Card.Header>
      <Card.Body>
        <Skeleton class="w-full aspect-video" />
      </Card.Body>
    </Card>
  )
}

Hold space for a paragraph#

Stack full-width bars and shorten the last line to mimic wrapping text.

import { Skeleton } from 'moraine'

export function SkeletonText() {
  return (
    <div class="flex flex-col gap-2 max-w-xs w-full">
      <Skeleton class="h-4 w-full" />
      <Skeleton class="h-4 w-full" />
      <Skeleton class="h-4 w-3/4" />
    </div>
  )
}

Placeholder a settings form#

Reserve label and control heights so the form layout is stable while values load.

import { Skeleton } from 'moraine'

export function SkeletonForm() {
  return (
    <div class="flex flex-col gap-7 max-w-xs w-full">
      <div class="flex flex-col gap-3">
        <Skeleton class="h-4 w-20" />
        <Skeleton class="h-8 w-full" />
      </div>
      <div class="flex flex-col gap-3">
        <Skeleton class="h-4 w-24" />
        <Skeleton class="h-8 w-full" />
      </div>
      <Skeleton class="h-8 w-24" />
    </div>
  )
}

Placeholder a data table#

Repeat a row of bars for each pending record.

import { Skeleton } from 'moraine'
import { For } from 'solid-js'

export function SkeletonTable() {
  return (
    <div class="flex flex-col gap-2 max-w-sm w-full">
      <For each={Array.from({ length: 5 })}>
        {() => (
          <div class="flex gap-4">
            <Skeleton class="flex-1 h-4" />
            <Skeleton class="h-4 w-24" />
            <Skeleton class="h-4 w-20" />
          </div>
        )}
      </For>
    </div>
  )
}

Shimmer a profile row while it loads#

Use variant="shimmer" when a sweep reads better than a pulse. Both animations honor reduced motion.

import { Skeleton } from 'moraine'

export function AnimationVariants() {
  return (
    <div class="flex gap-3 max-w-sm w-full items-center">
      <Skeleton variant="shimmer" class="rounded-full shrink-0 size-10" />
      <div class="flex-1 space-y-2">
        <Skeleton variant="shimmer" class="h-4 w-2/3" />
        <Skeleton variant="shimmer" class="h-3 w-full" />
      </div>
    </div>
  )
}

API Reference#

Props#

Renders a <div> element by default.

Prop