How to Create Animated Gradient Backgrounds in CSS
Build an animated gradient in CSS with background-position keyframes, calm timing, prefers-reduced-motion support, GPU-friendly layers and @property angles.
Read GuideGradient
Create animated CSS gradient backgrounds with keyframes and reduced-motion support.
Gradient
Create a moving background in seconds with this animated gradient generator, which blends three colors and slowly shifts them across the element using pure CSS. You control the colors, the angle and how many seconds one loop takes, and the preview plays the animation live. The copied code includes the oversized background-size, the @keyframes block, the animation property and a prefers-reduced-motion rule, so landing page builders and developers get a complete, accessible snippet with no JavaScript required.
For backgrounds behind text, choose three colors with similar lightness and set a long duration, somewhere around 10 to 20 seconds, so the motion stays in the background and text contrast barely changes during the loop. Check your text color against each of the three colors, since every one of them will pass behind the text at some point. Keep animated gradients to one or two sections per page, because repainting large areas on every frame uses extra battery on phones and laptops.
FAQ
Browsers do not smoothly animate from one gradient value to another by default, so the common technique is to make the gradient much larger than the element and animate its background-position. With background-size set to 400% 400%, shifting that position over time makes the colors appear to flow. This generator writes that technique for you.
Apply a linear-gradient as the background, enlarge it with background-size, then define @keyframes that move background-position from one side to the other and back. Attach the keyframes with the animation property and set it to repeat infinitely. Paste the generated CSS onto any element, such as a section or a div, to apply it.
prefers-reduced-motion is a CSS media query that detects when a visitor has asked their operating system to minimize animation. Constant motion can cause discomfort or distraction for some people, including those with vestibular disorders. The generated rule turns the animation off for those visitors while everyone else still sees it.
Animating background-position makes the browser repaint the element on every frame, which costs more than animating transform or opacity. On a small banner the cost is negligible, but a full-screen animated background on a low-power phone can drain battery. Use a slower duration and limit the effect to the areas where it adds the most value.
Learn more
Build an animated gradient in CSS with background-position keyframes, calm timing, prefers-reduced-motion support, GPU-friendly layers and @property angles.
Read GuideCreate a CSS gradient border that respects border-radius: border-image, the padding-box double background, and a mask trick for fully transparent centers.
Read Guide