Copied!
Guide

Animated gradient backgrounds: CSS, canvas or WebGL?

There are three ways to make a gradient that moves, and they cost very different amounts of battery. Here is when each one fits, with the CSS that works and the common version that does not.

← Blog
Title card: Animated gradients. Preview of the Shader gradient background element from the Enrichr Library.

December 4, 2026

3 min read3 methods compared

You can build an animated gradient background in three ways: with CSS, with a 2D canvas, or with a WebGL shader. Use CSS for a slow shift between a few colours. Use WebGL for the flowing, liquid look. Use a 2D canvas when you want that look without writing a shader. Each has a different cost, and the most copied CSS version is the most wasteful.

Try it on any site. The free animation library checker shows you which animation libraries actually run on a page (GSAP, Lenis, Framer Motion). Paste a URL, no sign-up for your first lookup.

How do the three compare?

MethodLookCostCode
CSSColours or blobs driftingLow, if you avoid repaintsA few lines
2D canvasWaves, plasma, soft noiseMedium; runs on the processor50 to 150 lines
WebGL shaderSmooth flowing noise, any complexityLow to medium; runs on the graphics card100 lines plus GLSL

What is the right way in CSS?

@property --a { syntax: "<angle>"; inherits: false; initial-value: 0deg; }
@property --c1 { syntax: "<color>"; inherits: false; initial-value: #0b3d2e; }

.bg {
  background: linear-gradient(var(--a), var(--c1), #c6f432);
  animation: drift 12s ease-in-out infinite alternate;
}
@keyframes drift { to { --a: 180deg; --c1: #1db954; } }

@media (prefers-reduced-motion: reduce) { .bg { animation: none; } }

@property tells the browser that --a is an angle and --c1 a colour, so it can blend between values. Without the registration the variables jump from one value to the next.

What is the common mistake?

The snippet found everywhere sets background-size: 400% 400% and animates background-position. It works, but the browser must repaint the full gradient on every frame, on the processor. On a large hero that can keep a laptop fan running. A cheaper way to get movement is two or three blurred, coloured circles moved with transform, which the graphics card handles.

When is WebGL worth it?

When you want colour that flows like liquid or silk. A fragment shader works out the colour of every pixel from a noise function and the time. It needs a canvas, about a hundred lines of setup and a short GLSL program. Three rules keep it light:

Which finished backgrounds can I copy?

ElementMethodWhat it does
Shader gradient backgroundWebGLA slow, flowing noise gradient from one fragment shader, with a CSS fallback.
Aurora backgroundWebGLSoft northern-lights ribbons that bend toward the pointer.
Iridescence sheenWebGLA soft, flowing thin-film colour shift.
Gradient wavesCanvasLayered, flowing sine-wave bands filled with gradients.
Plasma fieldCanvasA classic plasma colour field drawn at low resolution and scaled up.
Silk flowCanvasSmooth silky folds of light that drift and can be pulled by dragging.

All are free in the Enrichr Library, with live controls and copyable code.

Where to go next

FAQ

Can you animate a CSS gradient?

Not directly. Browsers do not blend between two background-image values. You can animate custom properties used inside the gradient if you register them with @property, or animate the position of an oversized gradient.

Why is my animated gradient using so much CPU?

Animating background-position or background-size makes the browser repaint the whole area every frame. Move a layer with transform instead, or use a shader.

How do sites make the flowing mesh gradient effect?

Usually with a WebGL fragment shader that mixes a few colours using animated noise. Some use a low-resolution canvas scaled up with a blur, which looks similar for less code.

Is a WebGL background bad for performance?

A single full-screen shader with simple noise is light for any recent phone. What hurts is running it at full retina resolution and never pausing it. Cap the pixel ratio and stop when hidden.