Skip to main contentSkip to docs navigation

Chassis

Placeholders that take the shape of content while it loads, with glow and wave animations, context colors, and widths from the sizing utilities.

@layer components
Context tokens

Introduction

A skeleton is a placeholder that stands in for content while it loads. It keeps the shape of the interface — the lines of a paragraph, the title of a card, the width of a button — so the layout does not shift when the content arrives.

Skeletons are CSS only. .skeleton draws a block in the foreground color at a low opacity. The width comes from the sizing utilities, the height from the font size of the element, and two wrapper classes animate it.

Key features

The skeleton reuses what the framework already has instead of adding its own API:

  • No JavaScript — the classes style the placeholder; showing and removing it belongs to the code that loads the content
  • Sized by existing utilities — the fraction and percentage widths, and the font-size classes for the height
  • Two animations — .skeleton-glow pulses the opacity and .skeleton-wave moves a highlight across
  • Context colors — .skeleton-{color} takes the color of a skeleton from the context palette
  • Component modifier — on a .button, .chip, or .badge, .skeleton keeps the background and the height of the component

Basic structure

Add .skeleton to an empty inline element and give it a width with a width utility such as .w-6/12, which sets the width in twelfths of the parent. On a component such as .button, add .skeleton to the component itself.

HTML
<p aria-hidden="true">
  <span class="skeleton w-6/12"></span>
</p>

<a class="button primary disabled skeleton w-4/12" aria-disabled="true"></a>

The same classes build the placeholder of a whole component. The second card repeats the structure of the first with skeletons in place of its text, and .skeleton-glow on a parent animates the skeletons inside it.

Placeholder

Card title

Some quick example text to build on the card title and make up the bulk of the card's content.

Go somewhere
HTML
<div class="card" style="width: 18rem;">
  <img src="..." class="card-img-top" alt="...">
  <div class="card-body">
    <h3 class="card-title">Card title</h3>
    <p>Some quick example text to build on the card title and make up the bulk of the card's content.</p>
    <a href="#" class="button primary me-auto">Go somewhere</a>
  </div>
</div>

<div class="card" aria-hidden="true" style="width: 18rem;">
  <img src="..." class="card-img-top" alt="...">
  <div class="card-body">
    <div class="card-title skeleton-glow">
      <span class="skeleton w-6/12"></span>
    </div>
    <p class="skeleton-glow">
      <span class="skeleton w-7/12"></span>
      <span class="skeleton w-4/12"></span>
      <span class="skeleton w-4/12"></span>
      <span class="skeleton w-6/12"></span>
      <span class="skeleton w-8/12"></span>
    </p>
    <a class="button primary disabled skeleton w-6/12" aria-disabled="true"></a>
  </div>
</div>

Width

A skeleton takes its width from the fraction widths (.w-6/12, with breakpoint variants such as .md:w-4/12), the percentage width utilities (.w-75), or an inline style.

HTML
<span class="skeleton w-6/12"></span>
<span class="skeleton w-75"></span>
<span class="skeleton" style="width: 25%;"></span>

Size

A skeleton is at least 1em tall, so its height follows the font size of the element. Apply the font size classes or the text utilities to match the content the skeleton stands in for.

HTML
<span class="skeleton w-100 font-xl"></span>
<span class="skeleton w-100"></span>
<span class="skeleton w-100 font-xs"></span>

<p class="font-sm">
  <span class="skeleton w-5/12"></span>
  <span class="skeleton w-3/12 text-sm"></span>
  <span class="skeleton w-3/12 text-lg"></span>
</p>

Animation

.skeleton-glow and .skeleton-wave show that loading is in progress. Both go on a parent of the skeletons: .skeleton-glow pulses the opacity of each skeleton inside it, and .skeleton-wave moves a highlight across the parent as one surface. .skeleton-glow also works on the skeleton itself.

HTML
<p class="skeleton-glow">
  <span class="skeleton w-100"></span>
</p>

<p class="skeleton-wave">
  <span class="skeleton w-100"></span>
</p>

Both animations stop when the user asks for reduced motion. A skeleton inside .skeleton-glow rests at its highest opacity, as a .skeleton with no animation, and .skeleton-wave drops its mask, so the placeholder stays fully visible with no highlight across it.

Chassis CSS respects user accessibility preferences by automatically disabling animations when the prefers-reduced-motion media query is detected. See the reduced motion guidelines in the accessibility documentation for implementation details.

Layout

Skeletons inside a grid or a flex container build the placeholder of a section. One .skeleton-glow on the container animates every skeleton in it.

HTML
<div class="grid skeleton-glow" aria-hidden="true">
  <div class="col-span-full md:col-span-3">
    <span class="skeleton w-100" style="height: 8rem;"></span>
  </div>
  <div class="col-span-full md:col-span-9">
    <span class="skeleton w-8/12 font-lg"></span>
    <span class="skeleton w-100"></span>
    <span class="skeleton w-10/12"></span>
    <span class="skeleton w-6/12"></span>
  </div>
</div>

Buttons

On a .button, .skeleton lowers the opacity and sets the wait cursor, and leaves the background of the button in place. An empty pseudo-element keeps the height of the button without its text, as it does for .chip and .badge. Combine it with the disabled state so the placeholder cannot be activated.

HTML
<div class="d-flex gap-md">
  <button type="button" class="button disabled skeleton w-3/12" aria-disabled="true" aria-label="Loading"></button>
  <button type="button" class="button primary disabled skeleton w-3/12" aria-disabled="true" aria-label="Loading"></button>
  <button type="button" class="button secondary disabled skeleton w-3/12" aria-disabled="true" aria-label="Loading"></button>
</div>

Theming

A skeleton is drawn in the foreground color of its context (--cx-fg-color). The .skeleton-{color} utilities set another color of the context palette through --cx-skeleton-color.

HTML
<span class="skeleton w-100"></span>
<span class="skeleton w-100 skeleton-default"></span>
<span class="skeleton w-100 skeleton-alternate"></span>
<span class="skeleton w-100 skeleton-primary"></span>
<span class="skeleton w-100 skeleton-secondary"></span>
<span class="skeleton w-100 skeleton-neutral"></span>
<span class="skeleton w-100 skeleton-danger"></span>
<span class="skeleton w-100 skeleton-success"></span>
<span class="skeleton w-100 skeleton-warning"></span>
<span class="skeleton w-100 skeleton-info"></span>
<span class="skeleton w-100 skeleton-black"></span>
<span class="skeleton w-100 skeleton-white"></span>

Accessibility

A skeleton carries no information, and the classes do not hide it from assistive technology. The markup and the script that loads the content do that work:

  • Set aria-hidden="true" on the skeleton, or on the container of a group of skeletons, so screen readers skip the placeholder.
  • Announce the loaded content, for example by inserting it into a region with aria-live="polite" or by setting aria-busy="true" on the region while it loads.
  • Give a skeleton the dimensions of the content it stands in for, so the page does not shift when the content replaces it.
  • A <button> skeleton stays focusable. The disabled attribute takes it out of the tab order; aria-disabled="true" with .disabled only announces and styles it as disabled.

CSS

This component can be customized through Sass variables at compile time.

Custom properties

This component exposes CSS custom properties to control its appearance at runtime.

--color: var(--skeleton-color, #{$skeleton-color});
--opacity-min: var(--skeleton-opacity-min, #{$skeleton-opacity-min});
--opacity-max: var(--skeleton-opacity-max, #{$skeleton-opacity-max});
--opacity-wave: var(--skeleton-opacity-wave, #{$skeleton-opacity-wave});

Sass variables

This component uses Sass variables in scss/config/_defaults.scss to define its defaults.

$skeleton-opacity-max:              .25;
$skeleton-opacity-min:              .15;
$skeleton-color:                    var(--fg-color);
$skeleton-opacity-wave:             .75;