How to Create an Animated Gradient
- Pick your colors — choose 2 or 3 gradient colors using the color pickers above. Contrasting colors create more dramatic animations.
- Set the direction — select one of 8 gradient directions using the direction pad (left to right, top to bottom, diagonal, and more).
- Adjust the speed — use the animation speed slider (1s to 15s) to control how fast the gradient shifts. Slower speeds work well for backgrounds, faster speeds for attention-grabbing elements.
- Preview the result — see your animated gradient applied to a full-width background and a border effect in real time.
- Copy the CSS — click the copy button on any preview to get the complete CSS code, including the keyframe animation.
What Are CSS Animated Gradients?
CSS animated gradients are backgrounds that smoothly transition their color positions over time using @keyframes and background-size. The technique works by creating a gradient larger than the element (typically 200-400% of its width) and animating the background-position property to shift the visible portion. This creates the illusion of flowing, moving colors without any JavaScript.
Animated gradients are widely used for hero sections, loading indicators, call-to-action buttons, and card borders. Because the animation runs entirely in CSS, it performs well and works across all modern browsers including Chrome, Firefox, Safari, and Edge.
Animated Gradient Borders with CSS
Animated gradient borders use a layered approach: a pseudo-element (::after) with the animated gradient sits behind the element, and the element itself has a solid background with slight inset. The visible gap between the inner background and the outer animated gradient creates the border effect. This technique avoids the limitations of border-image, which does not support border-radius.
Frequently Asked Questions
- How do I make a gradient animate in CSS?
- Set
background-sizeto a value larger than 100% (e.g., 200%) and use a@keyframesanimation that shiftsbackground-positionfrom 0% to 100%. The browser interpolates the position smoothly, making the gradient appear to move. - Do animated gradients affect performance?
- Animating
background-positiondoes trigger repaints, but the impact is minimal for most use cases. Avoid applying animated gradients to very large areas on low-powered devices. For best performance, keep the element size reasonable and usewill-change: background-positionto hint the browser. - Can I use animated gradients with Tailwind CSS?
- Tailwind doesn't include animated gradient utilities out of the box, but you can add custom keyframes and animation classes in your
tailwind.config.js. Define the keyframe animation undertheme.extend.keyframesand reference it intheme.extend.animation. - How do I control the animation speed?
- The animation speed is set by the
animation-durationproperty. A value of 1-4 seconds creates a fast, energetic effect. For subtle background movement, use 8-15 seconds. This generator lets you adjust the speed from 1s to 15s with a slider and see the result instantly.