Guide
How to make a mesh gradient in pure CSS
By Haikal Akif · Updated · 5 min read
Stack several radial-gradient() layers in one background-image, each anchored at a different point and fading to transparent, over a solid base color. The overlapping blends read as a soft, multi-point mesh, with no image file and no JavaScript.
What a "mesh gradient" is in CSS
In design tools, a mesh gradient is a grid of points, each with a color, blended smoothly between them. CSS has no mesh primitive, but layering radial gradients gives the same look: each layer is one colored "point" that fades out, and where layers overlap the colors mix.
The technique, step by step
Tinta builds every user-submitted mesh with one small function. Each color gets an anchor point; the first three spread over 55% of the box, the rest over 50%:
| Layer | Anchor (x y) | Fades out by |
|---|---|---|
| 1 | 10% 0% (top left) | 55% |
| 2 | 85% 5% (top right) | 55% |
| 3 | 45% 100% (bottom middle) | 55% |
| 4 | 0% 70% (left) | 50% |
| 5 | 95% 70% (right) | 50% |
| 6 | 50% 45% (center) | 50% |
For four pastel colors — #FBC2EB, #A6C1EE, #FDE68A and #C4B5FD — it produces exactly this:
.mesh {
background-color: #D8C9DC; /* the base the layers fade into */
background-image:
radial-gradient(at 10% 0%, #FBC2EB 0, transparent 55%),
radial-gradient(at 85% 5%, #A6C1EE 0, transparent 55%),
radial-gradient(at 45% 100%, #FDE68A 0, transparent 55%),
radial-gradient(at 0% 70%, #C4B5FD 0, transparent 50%);
}Layers listed first are painted on top. The 0 after each color starts it at full strength at the anchor; transparent 55% is where it has faded out. Raise that percentage for softer, larger blobs and lower it for tighter spots.
Choosing colors that blend well
- Stay within a lightness range. Pastels with pastels, or deep tones with deep tones; one very dark layer among pale ones looks like a stain.
- Analogous colors (neighbors on the wheel) give the smoothest meshes. One complementary layer adds a glow without turning the middle muddy.
- Set a background-color close to the average of your colors. Where every layer has faded, that base shows through.
- Three to six layers is the sweet spot; Tinta’s meshes hold three to six colors.
Browse the mesh gradient library for tested combinations, or filter by tone, such as pastel.
Fallbacks, text and accessibility
Radial gradients have been supported everywhere for over a decade, so the main fallback is the solid background-color, which also shows in Windows High Contrast and forced-colors modes. If text sits on the mesh, check it against the lightest and darkest regions with the contrast checker; a mesh changes color under the text, so the weakest point decides.
/* add a scrim for text on a busy mesh */
.mesh-hero {
background-image:
linear-gradient(rgb(255 255 255 / 0.55), rgb(255 255 255 / 0.55)),
radial-gradient(at 10% 0%, #FBC2EB 0, transparent 55%),
radial-gradient(at 85% 5%, #A6C1EE 0, transparent 55%);
}Performance and polish
- A CSS mesh weighs a few hundred bytes. A 1920px mesh exported as a PNG or JPEG is often hundreds of kilobytes, so CSS wins for hero sections.
- For an even softer look, put the mesh on a pseudo-element and add
filter: blur(40px), scaled up slightly so the blurred edges sit outside the box. Blur on a large area costs paint time, so avoid animating it. - Banding can appear in large, subtle meshes. A faint noise texture on top hides it.
- To animate, move the anchor positions with CSS custom properties registered through
@property, or cross-fade two mesh layers withopacity.
Generate one
The mesh gradient generator builds this CSS from your colors and lets you copy it. For straight-line blends, see the CSS gradients guide.