Blog
Wild & Free Tools

Animated CSS Gradient Background Generator — Shifting Color Backgrounds in 5 Lines

Last updated: April 2026 6 min read

Table of Contents

  1. The Basic Shifting Gradient Animation
  2. Applying to Hero Sections
  3. Animated Gradient Buttons
  4. Mesh Gradient Alternative in Pure CSS
  5. Performance and Accessibility Notes
  6. Frequently Asked Questions

An animated gradient background — where colors slowly shift and blend — takes about five lines of CSS and creates an effect that most people assume requires JavaScript or a design tool. The trick is background-size and @keyframes on background-position. Use our CSS gradient generator to build the colors first, then paste in the animation CSS below.

The Basic Shifting Gradient — 5 Lines of CSS

Here is the complete CSS for a smooth, looping gradient background:

.animated-gradient {
  background: linear-gradient(-45deg, #ee7752, #e73c7e, #23a6d5, #23d5ab);
  background-size: 400% 400%;
  animation: gradient 8s ease infinite;
}

@keyframes gradient {
  0% { background-position: 0% 50%; }
  50% { background-position: 100% 50%; }
  100% { background-position: 0% 50%; }
}

Why does this work? The background-size: 400% 400% makes the gradient four times larger than the element. The animation moves the visible window across this oversized gradient, creating the shifting color effect. Repeating the start position at 100% creates a seamless loop.

Adjust the four colors to match your brand. Build them in the gradient generator and copy the color values. The diagonal angle (-45deg) gives the most natural-looking movement — but try 90deg or 135deg for different feels.

Applying the Animated Gradient to a Full Hero Section

For a full-page hero with the animated gradient as the background, add height and width:

.hero {
  background: linear-gradient(-45deg, #667eea, #764ba2, #f093fb, #f5576c);
  background-size: 400% 400%;
  animation: gradient 10s ease infinite;
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
}

@keyframes gradient {
  0% { background-position: 0% 50%; }
  50% { background-position: 100% 50%; }
  100% { background-position: 0% 50%; }
}

For text readability on a gradient background, add a semi-transparent dark overlay or use white text with a text-shadow. The shifting gradient will show through the overlay while the text stays crisp.

Sell Custom Apparel — We Handle Printing & Free Shipping

Animated Gradient CTA Buttons That Grab Attention

Gradient buttons perform well in conversion rate tests when used for primary CTAs. An animated gradient button is even more attention-grabbing:

.cta-button {
  background: linear-gradient(270deg, #ee7752, #e73c7e, #23a6d5, #23d5ab);
  background-size: 300% 300%;
  animation: gradient 4s ease infinite;
  border: none;
  border-radius: 8px;
  padding: 14px 28px;
  color: white;
  font-weight: 600;
  cursor: pointer;
}

.cta-button:hover {
  animation-play-state: paused; /* pause on hover for focus */
}

@keyframes gradient {
  0% { background-position: 0% 50%; }
  50% { background-position: 100% 50%; }
  100% { background-position: 0% 50%; }
}

Pausing the animation on hover is a subtle UX touch that signals interactivity. Use a 3-4 second duration on buttons — fast enough to be noticeable but not distracting.

Creating a Mesh Gradient Effect in Pure CSS

True mesh gradients (like those in Figma or macOS wallpapers) require multiple overlapping radial gradients. Here is a CSS version that mimics the effect:

.mesh-gradient {
  background:
    radial-gradient(at 40% 20%, #667eea 0px, transparent 50%),
    radial-gradient(at 80% 0%, #f093fb 0px, transparent 50%),
    radial-gradient(at 0% 50%, #23d5ab 0px, transparent 50%),
    radial-gradient(at 80% 50%, #764ba2 0px, transparent 50%),
    radial-gradient(at 0% 100%, #ee7752 0px, transparent 50%);
  background-color: #0d1117;
}

Layer multiple radial gradients with transparent fade-outs over a dark background color. Each radial creates a soft "blob" of color. The overlapping semi-transparent layers blend to create the mesh effect. Animate the background-position of individual layers for a moving mesh.

Performance and Accessibility: What to Know

CSS gradient animations are GPU-accelerated by default in modern browsers — they perform extremely well with no impact on CPU. The animation runs on the compositor thread, which means it will not block JavaScript execution or cause layout reflow.

For accessibility, some users experience motion sensitivity. Add this to your stylesheet to respect user preferences:

@media (prefers-reduced-motion: reduce) {
  .animated-gradient {
    animation: none;
    background-position: 0% 50%;
  }
}

This pauses the animation for users who have enabled "Reduce Motion" in their system settings, giving you the static gradient as a fallback. One line of CSS makes your design significantly more accessible.

Build Your Gradient Colors — Free, No Signup

Generate the perfect color combination for your animated gradient. Copy the linear-gradient() CSS and paste it into the animation template above.

Open Free CSS Gradient Generator

Frequently Asked Questions

How do I make a gradient background animate smoothly?

Set background-size to 300-400% and use a @keyframes animation on background-position. Move from 0% 50% to 100% 50% and back to 0% 50% for a seamless loop. The gradient needs at least 3-4 color stops for the animation to look interesting.

Does CSS gradient animation affect page performance?

No. CSS background animations run on the GPU compositor thread and do not cause layout reflow or block JavaScript. They are among the most performant animation techniques in CSS.

Can I animate a radial gradient background?

Direct property animation of gradient color stops is not supported by CSS transitions or animations — only background-position and background-size can be animated. Use the background-position technique with a linear gradient, or stack multiple radial gradients and animate their positions separately.

How do I stop the animation on hover?

Add animation-play-state: paused to the :hover state of the element. This freezes the gradient at its current position when the user hovers, which signals interactivity on buttons and cards.

Launch Your Own Clothing Brand — No Inventory, No Risk