Components
Skeleton loading animation in CSS: shimmer, pulse and a clean handover to content
Build a skeleton loading animation in CSS: a shimmer that stays in sync, a pulse option, aria-busy, a 300 ms show delay and a crossfade to content. Live demo.
A skeleton screen is a grey outline of the content that is about to load: a circle where the avatar goes, a few bars where the text goes. It tells people what is coming and roughly where, so the page feels faster than a spinner in the middle of an empty box. The animation on top, a light sweep or a gentle pulse, signals that something is still happening.
This guide builds both versions in plain CSS, fixes the common "every line shimmers at a different speed" problem, and covers the parts that are easy to skip: screen readers, when to show the skeleton at all, and how to hand over to the real content without a jump.
Shipped the new onboarding flow. Motion specs are in the handoff file.
How the animation is put together
The skeleton has one looping animation. Everything else is a short transition when the content arrives.
| Part | Property | Duration | Delay | Easing |
|---|---|---|---|---|
| Bone shimmer | background-position: -200px → 360px | 1.5 s, infinite | 0 | linear |
| Bone pulse (alternative) | opacity: 1 → .5 → 1 | 1.6 s, infinite | 0 | ease-in-out |
| Skeleton appears | rendered at all | instant | 300 ms (in JS) | none |
| Skeleton out | opacity: 1 → 0 | 200 ms | 0 | ease-out |
| Content in | opacity: 0 → 1, translateY(4px → 0) | 250 ms | 0 | ease-out |
The skeleton and the content sit in the same grid cell, so they overlap exactly and the card never changes height during the swap. That only works if the bones match the real layout closely, which is the whole point of a skeleton anyway.
The HTML
<div class="skl" aria-busy="true">
<span class="skl-sr" role="status">Loading profile</span>
<div class="skl-bones" aria-hidden="true">
<div class="skl-row">
<span class="skl-bone skl-avatar"></span>
<span class="skl-col">
<span class="skl-bone skl-line" style="width:60%"></span>
<span class="skl-bone skl-line" style="width:38%"></span>
</span>
</div>
<span class="skl-bone skl-media"></span>
<span class="skl-bone skl-line" style="width:92%"></span>
<span class="skl-bone skl-line" style="width:74%"></span>
</div>
<div class="skl-content"><!-- real content goes here --></div>
</div>
Vary the line widths. Bars of identical width look like a table, not text, and the skeleton stops doing its job of previewing the layout.
The shimmer in CSS
The shimmer is a soft light band, drawn as a gradient, moved across each bone with background-position. The base grey is the background colour, and the band is a separate, non-repeating gradient on top.
.skl-bone {
display: block;
border-radius: 6px;
background: #2a2e37
linear-gradient(90deg, transparent, rgba(255, 255, 255, .09), transparent)
no-repeat;
background-size: 200px 100%;
animation: skl-sweep 1.5s linear infinite;
}
@keyframes skl-sweep {
from { background-position: -200px 0; }
to { background-position: 360px 0; }
}
.skl-avatar { width: 40px; height: 40px; border-radius: 50%; }
.skl-line { height: 10px; }
.skl-media { height: 120px; border-radius: 10px; }
The band starts fully off the left edge (-200px, its own width) and ends past the right edge of the widest bone. Because both ends are off-screen, the loop restarts invisibly and there is a short pause between sweeps, which reads as calmer than a band that is always on screen.
Use linear here. An eased sweep speeds up and slows down inside every bone, and the change of pace becomes a visible stutter at the loop point. The easing functions guide covers why looping motion and easing curves rarely mix.
Keeping the shimmer in sync
The most common version on the web sizes the gradient in percent, for example background-size: 200% 100% with positions from 100% to 0%. Each bone then sizes the gradient to its own width. A 300 px line and a 40 px avatar finish their sweep in the same 1.5 s, so the band moves several times faster across the line, and the card looks like each bar has its own idea of what loading means.
There are two fixes.
- Size the gradient in pixels, as above. Every bone moves the band at the same speed. Bones that share a left edge, like the lines in a paragraph, light up together. Bones further right, like the text next to an avatar, light up a little later, which reads as one sweep moving across the card.
- Use
background-attachment: fixed. The background is then positioned against the viewport instead of each bone, so all bones show slices of one shared gradient and the band passes through them as a single sweep. The cost: the positions in the keyframes now cover the viewport width, so tune the duration for wide screens, and some mobile browsers ignorefixedand fall back to normal scrolling backgrounds. Test it on the devices you support.
/* one shared sweep across every bone on the page */
.skl-bone {
background-attachment: fixed;
background-size: 400px 100%;
animation: skl-sweep-fixed 2s linear infinite;
}
@keyframes skl-sweep-fixed {
from { background-position: -400px 0; }
to { background-position: 100vw 0; }
}
Performance
Animating background-position repaints the bones on every frame. For a card or a short list this is cheap. For a long list of skeleton rows, either switch to the pulse below, or draw the band on a ::after pseudo-element and move it with transform: translateX(), which the browser can run on the compositor without repainting. Stop the animation the moment the content arrives; a skeleton that keeps shimmering under hidden content still costs paint time.
The pulse alternative
A pulse fades the bones in and out instead of sweeping a band across them. It is simpler, every bone is in sync by default, and opacity is one of the cheapest properties to animate.
.skl-bone--pulse {
background: #2a2e37;
animation: skl-pulse 1.6s ease-in-out infinite;
}
@keyframes skl-pulse {
0%, 100% { opacity: 1; }
50% { opacity: .5; }
}
Here ease-in-out is right, because the motion is a breath rather than a sweep: it should linger at each end and move through the middle.
Screen readers and aria-busy
A skeleton is a visual hint. To assistive technology, a stack of empty spans means nothing, or worse, a list of unlabelled items. Three small things fix that.
- Hide the bones. Put
aria-hidden="true"on the skeleton wrapper so it is skipped entirely. - Mark the region busy. Set
aria-busy="true"on the container while loading and remove it, or set it tofalse, when the content is in. It tells assistive technology that the region is being updated. Support varies between screen readers, so do not rely on it alone. - Announce the state. A visually hidden element with
role="status"that reads "Loading profile" and then "Profile loaded" covers the rest. Keep it short and only announce once per load, not once per card in a list.
When to show the skeleton
Showing a skeleton instantly is a common mistake. If the data arrives in 80 ms, the user sees a grey card flash for a few frames and then the content, which looks like a glitch. Wait about 300 ms before rendering the skeleton. If the data is back by then, render the content directly with no skeleton at all.
The reverse problem exists too: data arriving at 320 ms makes the skeleton appear for 20 ms. If that shows up in testing, keep the skeleton on screen for a minimum time, around 400 to 500 ms, once it has appeared.
Crossfading to the content
Do not just swap the skeleton for the content. Fade the skeleton out over about 200 ms and fade the content in over about 250 ms, with a 4 px rise. Because both sit in the same grid cell, the layout holds still and only the pixels change.
.skl { display: grid; }
.skl-bones, .skl-content { grid-area: 1 / 1; }
.skl-content {
opacity: 0; visibility: hidden; transform: translateY(4px);
transition: opacity 250ms ease-out, transform 250ms ease-out, visibility 0s 250ms;
}
.skl-bones { transition: opacity 200ms ease-out, visibility 0s; }
.skl.is-loaded .skl-bones { opacity: 0; visibility: hidden; transition: opacity 200ms ease-out, visibility 0s 200ms; }
.skl.is-loaded .skl-content { opacity: 1; visibility: visible; transform: none; transition: opacity 250ms ease-out, transform 250ms ease-out, visibility 0s; }
The visibility transitions keep the hidden layer out of the tab order and away from the pointer, while still letting the opacity fade play.
The React version
import { useEffect, useState } from 'react';
function useDelayedFlag(active, delay = 300) {
const [shown, setShown] = useState(false);
useEffect(() => {
if (!active) { setShown(false); return; }
const id = setTimeout(() => setShown(true), delay);
return () => clearTimeout(id);
}, [active, delay]);
return shown;
}
export function ProfileCard({ user, loading }) {
const showSkeleton = useDelayedFlag(loading);
if (loading && !showSkeleton) return <div className="skl" aria-busy="true" />;
return (
<div className={'skl' + (loading ? '' : ' is-loaded')} aria-busy={loading}>
<span className="skl-sr" role="status">{loading ? 'Loading profile' : 'Profile loaded'}</span>
<div className="skl-bones" aria-hidden="true">
<div className="skl-row">
<span className="skl-bone skl-avatar" />
<span className="skl-col">
<span className="skl-bone skl-line" style={{ width: '60%' }} />
<span className="skl-bone skl-line" style={{ width: '38%' }} />
</span>
</div>
<span className="skl-bone skl-media" />
<span className="skl-bone skl-line" style={{ width: '92%' }} />
</div>
<div className="skl-content">
{user && <><strong>{user.name}</strong><p>{user.bio}</p></>}
</div>
</div>
);
}
The empty placeholder during the first 300 ms keeps the card's space reserved, so nothing below it jumps when the skeleton or content appears. Give it a min-height that matches the loaded card.
Reduced motion
Under prefers-reduced-motion: reduce, drop the sweep and show static grey bones. A slow opacity pulse, around 2.5 s per cycle, is usually acceptable too, since it does not move anything across the screen, but static is the safe default. The skeleton still does its main job of previewing the layout. The reduced motion guide goes through the rest of a site, not just loaders.
@media (prefers-reduced-motion: reduce) {
.skl-bone { animation: none; background-image: none; }
.skl-bones, .skl-content { transition: none; transform: none; }
}
Match one you already like
Skeletons differ in small ways that are hard to judge by eye: the width of the band, the angle of the gradient, the pause between sweeps. If a product you admire gets it right, you can copy the animation from the page: Capture Motion records the shimmer or pulse while it plays, reads its keyframes, duration and easing, and exports it as CSS, React or GSAP code. For other ready components to customize and export, browse the gallery.
Questions
Is a shimmer or a pulse better for skeleton screens?
Both work. A shimmer reads as active loading and suits content-heavy lists; a pulse is calmer and cheaper to render. Pick one per product and use it everywhere.
Why does my shimmer look out of sync between lines?
If the gradient is sized in percent, each bone sizes it to its own width, so wider bones sweep faster. Size the gradient in pixels, or use background-attachment: fixed so every bone shares one gradient.
Should a skeleton appear immediately?
No. Wait around 300 ms before showing it. Most fast responses finish before then, and the user sees the content straight away instead of a skeleton that flashes for one frame.
Can I copy a skeleton animation from another website?
Yes. The Capture Motion Chrome extension records the keyframes, duration, delay and easing of the shimmer or pulse while it plays, and exports it as CSS, React, GSAP or JSON.
