Presets

CSS animation backgrounds

1 presets. Open one to tune it and copy the code.

Animated backgrounds add movement to a hero section or sign-up panel without images or video. The collection currently has one preset, the Animated gradient background: a three-color linear gradient at a chosen angle, enlarged to 300% so only part of it shows, whose background-position drifts across and back over eight seconds by default. The loop returns to its start inside the keyframe, so there is never a visible jump.

You can choose the three colors, the angle, the corner radius and the duration. Ambient backgrounds should be slow and low-contrast, so they sit behind your content instead of competing with it.

The same drifting-gradient technique powers the Gradient shift button, if you want a matching call to action. Copy the background as plain CSS, as Tailwind classes with an arbitrary gradient value, or as a React component using Motion.

How do I animate a background in CSS?

The most common way is to make a gradient larger than its element with background-size and animate background-position with @keyframes. That is what the Animated gradient preset does. You can also animate a pseudo-element behind the content with transform, which is cheaper for very large areas.

Will an animated background slow down my page?

Animating background-position repaints the area each frame. On a card-sized panel it is negligible; on a full-screen hero it can cost battery on low-end phones. Use long durations, consider a transform-based pseudo-element for large areas, and pause the animation under prefers-reduced-motion.

How do I keep text readable over an animated gradient?

Check contrast against every color the text will pass over, not only the first. Picking colors with similar lightness helps, as does a semi-transparent dark overlay or a text shadow on the heading. White text on mid-to-dark saturated colors is usually the safest combination for vivid gradients.