CSS Animation Example: Animated Mesh Gradient
The "Animated Mesh Gradient" provides a lush, fluid background that replaces static colors with soft, organic, melting blobs of color.
There is currently no native CSS way to animate between complex multi-stop gradients smoothly. Instead, we fake the mesh gradient effect by drawing individual HTML <div> elements and assigning them a radial-gradient() background that fades to transparent at the edges.
We wrap these blobs in a parent container and apply a massive blur(40px) to it via the filter property. This destroys the hard edges of the blobs and causes their colors to "bleed" and mix together.
From there, we simply assign an @keyframes block to slowly drift and scale each orb. We stagger them using different animation-duration and animation-delay values to ensure the pattern never looks like a synchronized repeating loop.
Here is the code to create the Animated Mesh Gradient.
Accessibility Considerations
While slow, continuous background motion can be distracting for some users, making it hard to concentrate on the text above it. prefers-reduced-motion is a CSS media feature used to detect if a user has enabled a setting on their device to minimize the amount of non-essential animation or motion.
It's best practice to stop the gentle drifting completely for users with the prefers-reduced-motion setting enabled. Even with the animation disabled, a static mesh gradient can still be highly attractive!
Here's what we used in our example:
@media (prefers-reduced-motion: reduce) {
.mesh-orb {
/* Turn off the drifting blobs completely */
animation: none;
}
}