Skip to main content

Components

Placeholders

Loading skeletons built from a single class — the glow and wave animations are pure CSS.

How it works

A placeholder is any element with .placeholder. It renders as a block of currentcolor at 50 % opacity, sized by its content or a width utility. The animations .placeholder-glow and .placeholder-wave are CSS keyframes, so they run with no script. Swapping the skeleton for real content is your job — the component is only the look.

  • Baseline: plain CSS. Works everywhere.
  • Enhancement: none needed. .placeholder-wave uses mask-image, which every current engine supports.
  • Fallback: none needed.

Example

A card before and after its content arrives.

Placeholder
Card title

Quick example text for the card. The main event starts after the intermission.

Go somewhere
HTML
<div class="card" style="width: 18rem;">
  <svg class="card-img-top" width="100%" height="180" xmlns="http://www.w3.org/2000/svg" role="img" aria-label="Placeholder" preserveAspectRatio="xMidYMid slice" focusable="false"><title>Placeholder</title><rect width="100%" height="100%" fill="#8a8f9f"></rect></svg>
  <div class="card-body">
    <h5 class="card-title">Card title</h5>
    <p class="card-text">Quick example text for the card. The main event starts after the intermission.</p>
    <a href="#!" class="btn btn-primary">Go somewhere</a>
  </div>
</div>

<div class="card" aria-hidden="true" style="width: 18rem;">
  <svg class="card-img-top" width="100%" height="180" xmlns="http://www.w3.org/2000/svg" role="img" aria-label="Placeholder" preserveAspectRatio="xMidYMid slice" focusable="false"><title>Placeholder</title><rect width="100%" height="100%" fill="#8a8f9f"></rect></svg>
  <div class="card-body">
    <h5 class="card-title placeholder-glow">
      <span class="placeholder col-6"></span>
    </h5>
    <p class="card-text placeholder-glow">
      <span class="placeholder col-7"></span>
      <span class="placeholder col-4"></span>
      <span class="placeholder col-4"></span>
      <span class="placeholder col-6"></span>
      <span class="placeholder col-8"></span>
    </p>
    <a class="btn btn-primary disabled placeholder col-6" aria-disabled="true"></a>
  </div>
</div>

Markup

Add .placeholder to a <span> and give it a width — grid columns (.col-6), width utilities (.w-75) or an inline style. Mark the whole skeleton aria-hidden="true" so a screen reader does not read empty spans, and announce the load state elsewhere.

HTML
<p aria-hidden="true">
  <span class="placeholder col-6"></span>
</p>

<a class="btn btn-primary disabled placeholder col-4" aria-disabled="true"></a>
.placeholder uses cursor: wait and min-height: 1em, so an empty span still has the height of a line of text. On a button the button padding sets the height instead.

Width

Any width method works. Mix them to vary the line lengths.

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

Color

The block is currentcolor, so any background utility or text colour recolours it.

HTML
<span class="placeholder col-12"></span>
<span class="placeholder col-12 bg-primary"></span>
<span class="placeholder col-12 bg-secondary"></span>
<span class="placeholder col-12 bg-success"></span>
<span class="placeholder col-12 bg-danger"></span>
<span class="placeholder col-12 bg-warning"></span>
<span class="placeholder col-12 bg-info"></span>
<span class="placeholder col-12 bg-light"></span>
<span class="placeholder col-12 bg-dark"></span>
<span class="placeholder col-12 bg-gold"></span>
<span class="placeholder col-12 bg-navy"></span>
<span class="placeholder col-12 bg-cream"></span>

Sizing

Height follows the font size of the parent. .placeholder-lg, .placeholder-sm and .placeholder-xs change the minimum height (1.2em, 0.8em, 0.6em).

HTML
<span class="placeholder col-12 placeholder-lg"></span>
<span class="placeholder col-12"></span>
<span class="placeholder col-12 placeholder-sm"></span>
<span class="placeholder col-12 placeholder-xs"></span>

Animation

Put .placeholder-glow or .placeholder-wave on the parent. Glow pulses the opacity of every .placeholder inside. Wave slides a gradient mask across the parent. Both are CSS @keyframes on a 2s loop, and both respect prefers-reduced-motion by stopping.

HTML
<p class="placeholder-glow">
  <span class="placeholder col-12"></span>
</p>

<p class="placeholder-wave">
  <span class="placeholder col-12"></span>
</p>

CSS

There are no CSS variables for placeholders. The rules are small enough to read in full:

.placeholder {
  display: inline-block;
  min-height: 1em;
  vertical-align: middle;
  cursor: wait;
  background-color: currentcolor;
  opacity: 0.5;
}

.placeholder-xs { min-height: 0.6em; }
.placeholder-sm { min-height: 0.8em; }
.placeholder-lg { min-height: 1.2em; }

.placeholder-glow .placeholder {
  animation: placeholder-glow 2s ease-in-out infinite;
}

.placeholder-wave {
  mask-image: linear-gradient(130deg, #000 55%, rgba(0, 0, 0, 0.8) 75%, #000 95%);
  mask-size: 200% 100%;
  animation: placeholder-wave 2s linear infinite;
}