Quick answer
Set a gradient as the background of an element:
/* linear: direction or angle, then colors */
background: linear-gradient(135deg, #6d28d9, #f43f5e);
/* smoother, more vivid blending */
background: linear-gradient(135deg in oklab, #6d28d9, #f43f5e);
/* radial and conic */
background: radial-gradient(circle at top left, #f59e0b, #7c3aed);
background: conic-gradient(from 90deg, #22d3ee, #a855f7, #22d3ee);Or build one visually with the free CSS gradient generator and copy the code.
linear-gradient()
A linear gradient blends colors along a straight line. The first argument sets the direction, followed by two or more color stops.
.hero {
background: linear-gradient(to right, #1e1b4b, #7e22ce, #f43f5e);
}The direction can be a keyword (to right, to bottom left) or an angle (135deg). 0deg points up and angles go clockwise, so 90deg is the same as to right.
Color stops can have positions. Without positions, colors are spread evenly. With them, you control exactly where each color sits, and two stops at the same position create a hard edge:
/* soft blend that lingers on violet */
background: linear-gradient(90deg, #1e1b4b 0%, #7e22ce 60%, #f43f5e 100%);
/* hard stripes */
background: linear-gradient(90deg, #f43f5e 50%, #1e1b4b 50%);radial-gradient()
A radial gradient blends outward from a center point. You can set the shape (circle or ellipse), the size and the position.
.glow {
background: radial-gradient(circle at 30% 20%, #fde68a, #f97316 30%, #1e1b4b 70%);
}Size keywords like closest-side, farthest-corner (the default) and explicit lengths such as circle 300px control how far the gradient reaches. Placing the center off-canvas, for example at 120% -20%, gives a soft light falling in from a corner.
conic-gradient()
A conic gradient sweeps colors around a center point, like the hand of a clock. Repeat the first color at the end for a seamless loop.
.ring {
background: conic-gradient(from 180deg at 50% 50%, #22d3ee, #a855f7, #f43f5e, #22d3ee);
}Conic gradients are great for color wheels, loading rings and pie charts (with hard stops), and as a subtle, blurred base for aurora-like backgrounds.
Avoid muddy middles with OKLab
By default, browsers blend gradient colors in sRGB. When two saturated colors far apart on the color wheel meet, the middle often turns gray or brown. Modern CSS lets you choose the interpolation color space right after the direction. in oklab gives perceptually even steps without a dark, muddy dip; in oklch also keeps the colors saturated by moving around the hue wheel:
/* perceptually even, no muddy dip */
background: linear-gradient(90deg in oklab, #2563eb, #f59e0b);
/* even and saturated */
background: linear-gradient(90deg in oklch, #2563eb, #f59e0b);
/* travel around the hue wheel: great for rainbows */
background: linear-gradient(90deg in oklch longer hue, #ef4444, #ef4444);Color interpolation in gradients works in current versions of Chrome, Edge, Safari and Firefox. Browsers that do not support it ignore the whole declaration, so put a plain gradient first as a fallback:
background: linear-gradient(90deg, #2563eb, #f59e0b);
background: linear-gradient(90deg in oklab, #2563eb, #f59e0b);Layer gradients for a mesh effect
CSS has no mesh gradient, but you can stack several radial gradients on top of a base color. Each one adds a soft blob of color, and together they look like a mesh:
.mesh {
background-color: #0b1030;
background-image:
radial-gradient(at 20% 25%, #7c3aed 0px, transparent 55%),
radial-gradient(at 80% 20%, #06b6d4 0px, transparent 50%),
radial-gradient(at 75% 80%, #f43f5e 0px, transparent 55%),
radial-gradient(at 25% 85%, #f59e0b 0px, transparent 45%);
}It is lightweight and responsive, but the blobs always stay round and the result has no grain. For truly organic, flowing shapes, see the mesh gradient guide.
Gradient text
Clip a gradient background to the text and make the text itself transparent:
.gradient-text {
background: linear-gradient(90deg in oklab, #a855f7, #f43f5e, #f59e0b);
-webkit-background-clip: text;
background-clip: text;
color: transparent;
}Gradient text in pure CSS
Add grain to a CSS gradient
Smooth CSS gradients can show banding and look a bit digital. You can add grain with an SVG noise filter as an extra background layer:
.grainy {
background:
url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='200' height='200'%3E%3Cfilter id='n'%3E%3CfeTurbulence type='fractalNoise' baseFrequency='0.9' numOctaves='3' stitchTiles='stitch'/%3E%3C/filter%3E%3Crect width='100%25' height='100%25' filter='url(%23n)' opacity='0.35'/%3E%3C/svg%3E"),
linear-gradient(135deg in oklab, #1e1b4b, #7e22ce, #f43f5e);
}It works, but the noise sits on top of the colors as a flat overlay and the SVG filter costs some rendering time on large areas. For the richest result, render the gradient with grain as an image: grain that follows the brightness of the colors looks far more like film. Compare the approaches below.

Animate a CSS gradient
Gradients cannot be transitioned directly, but you can make the background larger than the element and move it:
.animated {
background: linear-gradient(120deg, #6d28d9, #f43f5e, #f59e0b, #6d28d9);
background-size: 300% 300%;
animation: drift 12s ease-in-out infinite alternate;
}
@keyframes drift {
to { background-position: 100% 100%; }
}For animated angles or colors, register a custom property with @property so the browser can interpolate it. Respect prefers-reduced-motion and keep animations slow: fast-moving gradients are distracting and can trigger motion sickness.
CSS gradient or image?
| CSS gradient | Gradient image | |
|---|---|---|
| File size | Zero, just code | Small with WebP or AVIF |
| Responsive | Perfectly sharp at any size | Needs a large enough source |
| Shapes | Linear, radial, conic, stacked blobs | Anything: mesh, flow, light, glass |
| Grain and texture | Overlay only | Built in and color-aware |
| Best for | UI, buttons, simple backgrounds | Hero sections, brand visuals, wallpapers |
Frequently asked questions
Can CSS make mesh gradients?
Not natively. CSS supports linear, radial and conic gradients. You can approximate a mesh by layering several radial gradients over a base color, or use a gradient image for organic shapes.
How do I make a transparent gradient in CSS?
Use the transparent keyword or a color with alpha, for example linear-gradient(to bottom, rgb(0 0 0 / 0), rgb(0 0 0 / 0.6)). Fading to the same color with zero alpha avoids a gray tint.
What does 'in oklab' do in a CSS gradient?
It tells the browser to blend the colors in the OKLab color space instead of sRGB. Transitions look more even and avoid the dark, muddy middle of sRGB. Use in oklch to also keep the colors saturated.
How do I add grain to a CSS gradient?
Layer an SVG noise filter (feTurbulence) as an extra background image above the gradient. For richer, color-aware grain, use a gradient image rendered with grain.