Mesh Gradients in CSS: How to Create Soft, Blurry Gradient Backgrounds
Soft, multi-colored backgrounds that look like light shining through colored glass have become a signature of modern product design. Operating system wallpapers, app landing pages and conference branding all use them. They are usually called mesh gradients, and while CSS has no mesh gradient function, you can create a convincing version with a few lines of code and no images at all.
What a mesh gradient is
A regular linear gradient blends colors along one straight line. A radial gradient blends outward from a point. Both are one-dimensional in a sense: color only changes along one direction.
A true mesh gradient, as found in Adobe Illustrator, CorelDRAW and some newer design tools, is two-dimensional. The designer places a grid of points over a shape, assigns a color to each point, and the software blends smoothly between all of them. Because the grid can be bent, the colors can flow along curves. It is the technique illustrators use to paint realistic objects with vector shapes.
On the web, the word is used more loosely for any soft background where several colors blend in different directions.
| Gradient type | Color changes along | Typical look | Native CSS? |
|---|---|---|---|
| Linear | One straight line | Sunset bands, stripes | Yes |
| Radial | Outward from a point | Spotlights, vignettes | Yes |
| Conic | Around a center point | Color wheels, pie charts | Yes |
| Mesh (true) | A deformable 2D grid of points | Organic, painterly | No |
| Layered radial (“CSS mesh”) | Several overlapping blobs | Soft aurora, glassy light | Yes, by stacking |
How to build one in CSS
The trick is to stack several radial gradients, each starting with a color at a chosen position and fading to transparent, on top of a base background color:
background-color: #f3ecdf;
background-image:
radial-gradient(at 18% 22%, #e0a96d 0px, transparent 55%),
radial-gradient(at 82% 30%, #c9b28a 0px, transparent 55%),
radial-gradient(at 30% 85%, #8a6d3b 0px, transparent 55%),
radial-gradient(at 75% 80%, #f6d5b5 0px, transparent 55%);Each radial-gradient(at x y, …) places a soft blob of color. Where blobs overlap, the browser composites them, creating the blended mesh look. The mesh gradient generator above builds exactly this code, lets you shuffle positions, and can export the result as a PNG for slides or wallpapers.
Why “transparent” matters
Older advice warned that fading to the keyword transparent could produce a greyish fringe, because transparent is black at zero opacity. Modern browsers interpolate gradients in premultiplied alpha, which avoids that problem, so transparent is safe in current browsers. In canvas drawing and some older tools, it is still better to fade to the same color at zero alpha.
Size and performance
A CSS mesh gradient is a few hundred bytes. A comparable 1920×1080 PNG wallpaper is often 200 KB to over 1 MB, because smooth gradients don’t compress well in PNG, and JPEG versions can show blocky artifacts. CSS gradients are also resolution-independent, so they stay smooth on 4K and Retina screens.
Browsers render gradients on the GPU, so a static gradient background is cheap. Animating the positions of several large radial gradients forces repainting on every frame, which can drain battery on phones; if you animate, keep it slow and subtle, or animate a pre-rendered layer with transform instead.
The banding problem
Very soft gradients across large areas can show banding: visible stripes where the color steps from one value to the next. It happens because standard displays and images use 8 bits per channel, only 256 levels, and a gentle gradient across 1,000 pixels has to repeat each level over several pixels. Dark, low-saturation gradients are the worst affected.
Fixes:
- Add noise. A subtle grain overlay breaks up the steps so the eye sees a smooth blend. Our noise texture generator creates a tileable grain you can layer on top. We explain why this works in grain textures and gradient banding.
- Increase color difference. Banding is most visible when the two colors are very close.
- Avoid exporting smooth gradients to JPEG at low quality, which adds block artifacts on top of the banding.
Designing with mesh gradients
Pick related colors. Mesh gradients look most natural with analogous colors (neighbours on the color wheel) or several tints of one hue plus a single accent. A palette from the color palette generator in analogous mode is a good start.
Control lightness. If text will sit on the gradient, keep the whole area either light (for dark text) or dark (for white text). A gradient that goes from very light to very dark makes text contrast impossible everywhere.
Give text a calm zone. Place the strongest color blobs away from where headlines sit, or add a semi-transparent panel behind text. A glassmorphism card works well on mesh backgrounds.
Check contrast at the worst point. Use the contrast checker with the color directly behind the lightest or darkest letters.
CSS mesh versus image mesh
| Aspect | CSS layered radial | Exported PNG/JPEG |
|---|---|---|
| File size | Under 1 KB | 100 KB – 1 MB+ |
| Sharpness at any size | Perfect | Fixed resolution |
| Editable later | Change one value | Re-export |
| Works in email, slides, social | No | Yes |
| True curved mesh control | No | Yes, if made in a vector tool |
Use CSS for websites and apps, and export images for everything that can’t render CSS: presentations, social posts, email headers and desktop wallpapers.