CSS Animation Example: The Skeleton Wave
The "Skeleton Wave" (or shimmer) is a modern loading pattern that displays a simplified mockup of the content layout while the actual data fetches.
This animation creates the illusion of a light beam sweeping across the elements. We achieve this by giving each placeholder element a solid base color and overlaying it with a semi-transparent linear gradient (linear-gradient()). We use background-size: 200% to make the gradient larger than the element, and then animate its background-position from left to right using @keyframes.
Here is the code to create the Skeleton Wave animation.
Accessibility Considerations
Rapid, high-contrast flashing can be an issue, but a soft, slow shimmer is generally well-tolerated. However, it's safest to respect the prefers-reduced-motion media query by removing the animation entirely for users who have requested their system minimize non-essential motion.
A static skeleton screen still effectively communicates that content is loading without relying on movement. Here's how we handled it in our code example:
@media (prefers-reduced-motion: reduce) {
.skeleton-line, .skeleton-avatar {
animation: none;
background-image: none; /* Remove the gradient so it's a solid block */
}
}