Gradients are one of the cheapest ways to make a page feel finished. A hero section with a soft two-colour blend, a button that looks slightly raised, a progress ring or a subtle overlay that keeps white text readable over a photo: all of these can be done with a single CSS property and no image files at all.
The syntax, though, has a few quirks. Angles do not point where many people expect, colour stops can be written several ways, and some colour pairs turn muddy in the middle. This guide explains how the three gradient types work, how to build one visually and copy the code, and how to avoid the common visual problems.
Gradients are images, not colours
In CSS, a gradient is generated as an image. That is why it goes in background or background-image, not background-color:
.hero {
background-color: #2193b0; /* fallback */
background-image: linear-gradient(135deg, #2193b0, #6dd5ed);
}
Because gradients are images, you can layer several of them, separated by commas, and combine them with photos. The first layer listed is drawn on top.
The three gradient types
Linear gradients
linear-gradient() blends colours along a straight line. The first argument is the direction:
to right,to bottom leftand similar keywords name a side or corner.- An angle such as
90degsets the direction of the gradient line. 0deg points up and angles increase clockwise, so90degruns left to right and180degruns top to bottom (the default).
Radial gradients
radial-gradient() spreads out from a centre point. You can choose the shape (circle or ellipse) and the centre position (at top left, at center and so on). Radial gradients are good for spotlights, vignettes and soft glows behind a product image.
Conic gradients
conic-gradient() sweeps colours around a centre point, like the hands of a clock. from 0deg sets the start angle. Conic gradients are ideal for pie charts, colour wheels and progress rings, which previously needed SVG or images.
Colour stops
Each colour can have a position:
linear-gradient(90deg, #ff9933 0%, #ffffff 50%, #138808 100%)
If two neighbouring stops share a position, the change is instant, giving hard stripes instead of a blend. Adding repeating- in front (repeating-linear-gradient) repeats the pattern, which is how CSS stripes and checkerboards are made.
Build a gradient visually
Adjusting numbers in a stylesheet and refreshing is slow. The CSS Gradient Generator shows the result live and writes the code.
- Open the CSS Gradient Generator.
- Under Gradient type, choose Linear, Radial or Conic. Tick Repeating gradient if you want the pattern to repeat.
- For linear gradients, drag the Angle slider or click one of the quick angle buttons (0°, 45°, 90° and so on). For conic gradients, set the Start angle. For radial gradients, pick a Shape (Circle or Ellipse); radial and conic gradients also have a Centre position.
- In Colour stops, drag the handles along the bar to move stops, or click the bar to add a new one. Select a stop to change its Selected stop colour, Position and Opacity. Add and Remove manage stops; a gradient always keeps at least two.
- For inspiration, click one of the Presets such as Sunset, Ocean or Rainbow wheel, or press Random.
- Check the Live preview. Transparent areas show a checkerboard so you can see opacity clearly. Reset returns to the first preset.
- Copy the finished rule from CSS code.
Stops can also be moved with the arrow keys once a handle is focused, and the Delete key removes the selected stop.
Other ways to make gradients
Browser developer tools
Chrome, Edge and Firefox let you click the colour swatch next to a gradient in the Styles panel and adjust stops directly on a live page. This is the best option when you are fine-tuning an existing site, because you see the gradient in context with real content.
Design software
Figma, Sketch and similar tools can export gradients as CSS. The output is usually accurate for linear gradients, but check angles: design tools and CSS do not always measure them the same way.
Writing it by hand
Once you know the syntax, simple two-colour gradients are quick to type. A generator earns its keep when you have three or more stops, transparency, or radial and conic shapes that are hard to picture.
Tips for better-looking gradients
Avoid the grey middle
Blending two colours that sit on opposite sides of the colour wheel, such as blue and orange, often produces a dull grey or brown midpoint. Add a third stop in between with a brighter, related colour, or pick neighbouring hues. Modern browsers also support interpolation in other colour spaces, for example linear-gradient(in oklch, …), which tends to keep mid-tones vivid. Check current browser support before relying on it.
Reduce banding
Large, subtle gradients can show visible steps ("banding"), especially on dark backgrounds. Using colours slightly further apart, adding an intermediate stop, or layering a very faint noise texture helps.
Keep text readable
Text over a gradient must meet contrast guidelines at both ends, not just in the middle. Test the lightest and darkest stops against your text colour with a colour contrast checker. A semi-transparent dark overlay gradient over photos is a common way to keep white headings legible.
Always set a fallback colour
A plain background-color before the gradient keeps the section usable if the gradient fails to load in an old email client or is overridden by a user style. Email clients in particular have patchy gradient support.
Pair with other effects carefully
Gradients combine well with shadows and rounded corners. The box shadow generator and border radius generator produce matching CSS, and a colour converter helps you pick tints and shades of the same hue for your stops.
Frequently asked questions
Why does 90deg go left to right?
In CSS, 0deg points straight up and angles turn clockwise. So 90deg points right, meaning the gradient starts on the left and ends on the right.
Can I animate a CSS gradient?
Browsers cannot smoothly animate between two gradient images directly. Common workarounds are animating background-position on an oversized gradient, or animating custom properties registered with @property.
How do I make hard stripes instead of a blend?
Give two neighbouring colour stops the same position, for example #000 50%, #fff 50%. Combine this with a repeating gradient for evenly spaced stripes.
Do gradients slow down a website?
They are drawn by the browser, so there is no image download. Very large, heavily layered or animated gradients can cost some rendering time, but a normal background gradient is lighter than an image.
What is a conic gradient used for?
Anything that sweeps around a centre point: pie charts, colour wheels, loading spinners and progress rings.