Full answer
A skeleton screen shows grey shapes in the layout of the content while data loads. It makes the wait feel shorter and reserves the right space, so the page does not jump when the real content arrives.
How to build it:
- Make shapes with simple elements and a grey background: a bar for a title, shorter bars for text lines, and a square for an image. Give them the same height and width as the real content, so the layout does not shift.
- Add a soft shimmer. A
linear-gradientbackground that is larger than the element and moves with@keyframesonbackground-positionis a common approach. - Respect users who ask for less motion. Turn the animation off in
@media (prefers-reduced-motion: reduce), and keep the plain grey blocks.
Accessibility needs attention. Grey shapes mean nothing to a screen reader user, so:
- Set
aria-busy="true"on the region that is loading. When the content is ready, replace the skeleton, and setaria-busy="false"or remove it. - Hide the placeholder shapes from assistive technology with
aria-hidden="true", or make them empty elements with no text. - If it matters, announce the loading and the result with a polite live region, such as a visually hidden "Loading courses" message.
Do not leave a skeleton forever. If loading fails, replace it with an error message and a retry button.
The card shows a title bar and two text bars with a moving shine. With reduced motion, they are still and grey. A screen reader reads the status message and knows the region is busy.
When the data arrives, replace the placeholder with the real content, update the status text, and set aria-busy to false.
<style>
.sk { background: linear-gradient(90deg, #e5e5e5 25%, #f2f2f2 50%, #e5e5e5 75%); background-size: 200% 100%; animation: shimmer 1.2s linear infinite; border-radius: 4px; }
.sk.title { height: 20px; width: 60%; margin-bottom: 8px; }
.sk.line { height: 12px; width: 100%; margin-bottom: 6px; }
@keyframes shimmer { from { background-position: 200% 0; } to { background-position: -200% 0; } }
@media (prefers-reduced-motion: reduce) { .sk { animation: none; } }
</style>
<section id="card" aria-busy="true" aria-labelledby="h">
<h2 id="h" style="position:absolute;left:-9999px">Course card</h2>
<div aria-hidden="true">
<div class="sk title"></div>
<div class="sk line"></div>
<div class="sk line" style="width:80%"></div>
</div>
<p id="status" role="status" style="position:absolute;left:-9999px">Loading course</p>
</section>Checked by reading the computed animation, with and without the reduced motion preference emulated in Chrome. No screen reader was run. Run in Chrome 156 (headless) as a page; the snippet is wrapped in a minimal HTML document with doctype, charset and viewport meta tag. Two full runs gave identical results, and the measured values in the answer come from them.
Key points
- Skeleton blocks reserve space and reduce layout shift.
- A moving gradient background gives a shimmer.
- Disable the animation in prefers-reduced-motion: reduce.
- aria-busy and aria-hidden keep the placeholder quiet for screen readers.
- Replace it with an error and retry if loading fails.
Common mistakes
- Using an infinite shimmer with no reduced motion option.
- Skeleton shapes with different sizes from the real content, so the page still jumps when loaded.
- Leaving the skeleton forever when a request fails.
Follow-ups
- How would you handle a failed request?
- Why use a gradient and background-position instead of animating width?
Tips
- Link skeletons to layout shift: same size as the real content.
- Mention aria-busy, aria-hidden and a status message.