Code

How to Make Mesh Gradients

What a mesh gradient is, how to fake one with layered radial gradients in CSS, and how to export it cleanly.

By The White Screen Background crew4 min read
How to Make Mesh GradientsCodeHow to Make MeshGradients

Those dreamy, blobby backgrounds where colours melt into each other like a lava lamp? Those are mesh gradients. They look complex, but you can build a convincing one with a few lines of CSS. Let’s make one from scratch.

What is a mesh gradient?

A regular gradient blends colours along one line or out from one point. A mesh gradient blends several colours from several points at once, so the transitions curve and flow.

The name comes from design software, where a true gradient mesh is a grid of points you can colour and drag individually. Browsers don’t have a built-in mesh gradient. What we do on the web is fake it by stacking soft radial gradients. The result is close enough that almost nobody can tell.

The recipe

  1. Start with a base colour.
  2. Add three to five large, soft blobs of colour at different positions.
  3. Fade each blob to transparent so they blend into each other.
  4. Optional: add grain.

Step 1: one blob

.mesh {
  background-color: #FFFFFF;
  background-image:
    radial-gradient(at 20% 25%, #3B82F6 0px, transparent 50%);
}

at 20% 25% places the blob’s centre. It fades from blue at the centre to transparent halfway to the farthest corner.

Step 2: add more blobs

.mesh {
  background-color: #FFFFFF;
  background-image:
    radial-gradient(at 20% 25%, #3B82F6 0px, transparent 50%),
    radial-gradient(at 80% 15%, #EC4899 0px, transparent 50%),
    radial-gradient(at 70% 80%, #8B5CF6 0px, transparent 50%),
    radial-gradient(at 10% 85%, #D5F5E8 0px, transparent 50%);
}

Each line is a layer. Where they overlap, they mix. That’s a mesh gradient.

Step 3: tune it

ChangeEffect
Move the at x% y% positionsChanges the composition
Raise the 50%Bigger, softer blobs with more overlap
Lower itSmaller, more distinct blobs
Use rgba() with alpha under 1Gentler, more pastel result
Change the base colourSets the overall mood: white is airy, navy is dramatic

Tips for a good-looking mesh

  • Three to five colours. More gets chaotic.
  • Keep hues related. Neighbours on the colour wheel blend cleanly. Opposites go muddy where they meet.
  • Vary the sizes. One large blob, a couple of medium, one small. Even sizes look mechanical.
  • Place blobs off-centre. Corners and edges look more natural than a tidy grid.
  • Leave a calm zone. If text goes on top, keep one area light and quiet.
  • Match lightness. Pastels are ideal: lavender, peach, mint and sky together are almost impossible to get wrong.

A soft pastel mesh

.mesh-pastel {
  background-color: #FFFFFF;
  background-image:
    radial-gradient(at 15% 20%, #E6E0FF 0px, transparent 55%),
    radial-gradient(at 85% 10%, #FFD6E7 0px, transparent 55%),
    radial-gradient(at 80% 85%, #FFE0CC 0px, transparent 55%),
    radial-gradient(at 15% 90%, #D5F5E8 0px, transparent 55%);
}

A dark, dramatic mesh

.mesh-dark {
  background-color: #0F172A;
  background-image:
    radial-gradient(at 20% 20%, rgba(59,130,246,.7) 0px, transparent 50%),
    radial-gradient(at 85% 30%, rgba(236,72,153,.6) 0px, transparent 45%),
    radial-gradient(at 50% 90%, rgba(139,92,246,.7) 0px, transparent 55%);
}

Step 4: add grain

A little noise makes a mesh look printed and hides banding. Put an SVG noise layer first in the list so it sits on top:

background-image:
  url("data:image/svg+xml,...feTurbulence..."),
  radial-gradient(at 20% 25%, #3B82F6 0px, transparent 50%),
  ...;

The Noise pattern in the studio gives you a ready-made noise layer to copy.

The other method: blurred shapes

You can also make a mesh by placing coloured circles and blurring them heavily:

.blob {
  position: absolute;
  width: 40vw; aspect-ratio: 1;
  border-radius: 50%;
  background: #8B5CF6;
  filter: blur(80px);
  opacity: .5;
}

This is how the drifting blobs behind our home page hero are made. The advantage is you can animate each blob with transform. The cost is performance: large blurs are heavy, so use only a few, animate only transform, and reduce them on phones.

Animating a mesh

  • For the radial-gradient method, make the element larger than its container and slowly animate background-position, or animate the positions with CSS custom properties registered through @property.
  • For the blurred-shapes method, animate transform: translate() scale() on each blob over 20 to 40 seconds.
  • Always respect prefers-reduced-motion and stop the animation for people who ask for less movement.

Exporting your mesh

Need a PNG for a thumbnail or a slide?

  1. Apply the CSS to a full-screen element.
  2. Open it fullscreen in your browser.
  3. Take a screenshot, or use your browser’s developer tools to capture a full-size screenshot of the element.

For solids, linear gradients and patterns, the studio exports PNGs directly at any size. Sizes for each platform are in background sizes for every social platform.

Keep text readable

Mesh gradients change colour underneath your words, so contrast varies across the text. Put text over the calmest, lightest or darkest area, or add a semi-transparent panel behind it. Details in accessible colour contrast.

Common mistakes

  • Too many colours, so it looks like a spill.
  • Opposite hues overlapping into grey-brown.
  • Blobs all the same size in a neat grid.
  • No quiet area for content.
  • Heavy animated blurs on mobile.

The takeaway

A mesh gradient on the web is a stack of soft radial gradients over a base colour. Three to five related colours, varied sizes, off-centre positions, a touch of grain. Learn the building blocks in the CSS gradient syntax guide, then start layering.

FAQ

No. On the web you simulate one by layering several radial gradients or blurred shapes.

Three to five related colours work best.

Layered radial gradients are light. Large animated blurs are heavier, so use them sparingly.

Keep reading

Partner with us

Get your brand in front of creators

We run a few clearly labelled sponsored links, featured tool spots and newsletter shout-outs for design tools, streaming gear and creator apps. If our readers would actually use it, let’s talk.

One email a month. No spam, unsubscribe any time.