Skip to main content
Color & Image

CSS Gradients vs Generated Images: When to Use Which

A gradient looks like the simplest thing in front-end work: pick two colors, let the browser blend them, ship it. Then someone opens the page on a three-year-old Android, or a designer hands you a mesh background with five color stops, or the PNG you exported to "save the browser the trouble" turns out to weigh 4 MB — and the simple choice gets expensive. Both approaches are valid. They solve different problems, and mixing them up is what causes the rework.

What CSS gradients actually are

linear-gradient(), radial-gradient(), and conic-gradient() are not images. They are paint instructions. The browser computes the color at every pixel at render time, from your stops and angles. That has three practical consequences.

  • Zero network cost. The gradient ships as bytes in your stylesheet. A five-stop linear gradient is roughly 120 bytes after minification — a PNG of the same gradient, at 1920×1080, can easily be 200 KB to 2 MB depending on noise and banding.
  • Resolution independence. It stays sharp at any viewport size, any device pixel ratio, any zoom level. An image gradient scales, and scaling a gradient is where the banding and blur show up.
  • Cheaper to change than to version. Change #ff6b6b to #ff8e53 in CSS and you're done. Change the gradient image and you re-export, re-upload, invalidate CDN, and hope nobody has the old file cached.

The catch: the browser paints gradients on the CPU/GPU on every paint. A full-viewport gradient that repaints on scroll (because it sits behind a position: fixed layer or an element with backdrop filters) costs per frame. Usually negligible. On low-end phones with layered compositing, it can show up in profiles.

What generated images give you

A gradient as a file — PNG, WebP, AVIF, or JPEG — is frozen pixels. That sounds like a downgrade, and for a simple two-stop linear background it is. But it buys you things CSS can't do at all:

  • Mesh and multi-point gradients. Three or four radial gradients layered over each other, blurred, composited — CSS can approximate this with stacked background layers, but the result is verbose, and matching a designer's mock exactly is a day of fiddling. A generated image matches pixel-for-pixel.
  • Noise and dithering. Banding is the classic CSS gradient failure: on a dark, wide, low-contrast gradient, 8-bit color channels produce visible stripes. A generated image can be dithered or have subtle noise baked in, which hides banding better than any CSS trick. This is the number one reason "just use CSS" fails on dark themes.
  • Paint-free cost. A decoded image sits on the GPU as a texture. It doesn't repaint when the underlying layout changes.

The cost is payload, and payload is measurable. Before you ship one, check the actual file size with an image optimizer — a gradient PNG is almost never the right format; WebP or AVIF at quality 70-80 usually cuts it 5-10× with no visible loss. A 300 KB background image is fine for a landing hero. A 2 MB one is not, and nobody will tell you until the Lighthouse run.

Banding: where the decision usually gets made

If your gradient is dark, wide, and low-contrast — hero backgrounds, section dividers on dark themes — you will hit banding with pure CSS. The workarounds, in order of how well they work:

  1. Generated image with baked-in noise or dithering (best result, costs payload).
  2. Same gradient, split into two CSS layers with slightly different stops — sometimes masks the stripes, sometimes makes them worse.
  3. A transparent noise overlay (a small tiled PNG with opacity: 0.02) on top of the CSS gradient — cheap, and nearly always enough.

If your gradient is bright, short-range, or high-contrast — buttons, badges, small cards — CSS wins outright. Banding needs distance to appear, and small elements don't have it.

The color problem nobody plans for

A second failure mode is subtler: the gradient looks different after handoff. You write linear-gradient(90deg, #4f46e5, #ec4899), it matches the mock, and then a designer asks for the same blend in HSL — or the print team needs the CMYK equivalent and the conversion shifts the midtones. Browsers interpolate in sRGB by default; if the two endpoints are far apart in hue, the blend passes through muddy gray. in oklch (supported in all evergreen browsers) interpolates in a perceptual space and fixes most of it:

linear-gradient(in oklch, #4f46e5, #ec4899)

Try both variants side by side before committing — the difference on purple-to-green blends is large. If you need to move endpoint colors between formats during the back-and-forth, a color converter saves you from hand-misconverting hex to HSL and shipping the wrong one. And when the endpoints themselves are uncertain, generate a coherent set first with a CSS gradient generator instead of guessing stops by eye — it's faster than iterating in DevTools and gives you working background-image syntax immediately.

The hybrid that most production sites converge on

The pattern that holds up in real deployments: CSS gradient for the base layer, tiny generated texture for the detail layer.

background-image: url(noise.webp), linear-gradient(135deg, #1e293b, #0f172a);

The noise tile is 2-5 KB, tiles seamlessly, hides the banding the second layer would produce, and the whole thing weighs less than a single exported gradient image would. Hero backgrounds get one step better: CSS for the responsive base, and one <picture> with a pre-rendered mesh image in WebP/AVIF for screens wider than a breakpoint.

Decision rules

  • Two or three straight stops, any size → CSS. Always.
  • Buttons, badges, small components → CSS, plus oklch interpolation if the hues are far apart.
  • Full-bleed dark background, low contrast → CSS plus a noise overlay, or a dithered generated image.
  • Designer mesh gradient, multi-color, photographic smoothness → generated image, WebP/AVIF, compressed hard.
  • Anything that animates between gradients → CSS (transitions only work on CSS gradients, not on images swapping).

None of this is about taste. It's about where the cost lands: CSS gradients cost bytes and paint time, images cost kilobytes and cache invalidation. Measure both on your actual page, assign each layer the job it does well, and stop treating the choice as an either-or.