The three gradient types
They differ in the shape the colours travel along, and each suits a different job.
CSS gradient types and what they suit
| Type |
How colours travel |
Typical use |
| linear-gradient |
Along a straight line, in a direction or at an angle |
Hero backgrounds, buttons, section dividers |
| radial-gradient |
Outward from a centre point |
Spotlights, glows, soft vignettes |
| conic-gradient |
Around a centre point, like a clock face |
Pie and donut charts, colour wheels, sweep effects |
How angles work in CSS
CSS gradient angles are measured clockwise from "up". 0deg points to the top, 90deg to the right, 180deg to the bottom, 270deg to the left. This trips people up because it is not the mathematical convention, where 0 points right and angles run anticlockwise.
The keyword directions are shorthands for exactly the same thing: to right is 90deg, to bottom is 180deg. Keywords also behave slightly differently on non-square boxes — to bottom right always points at the actual corner, whereas a fixed angle does not follow the box as it resizes.
Colour stops and hard stops
A colour stop is a colour and the position along the gradient where it sits. Between two stops the browser blends smoothly; the positions control where each colour is at full strength.
Two useful patterns come out of that. Putting two stops at the same position creates a hard stop — a crisp line with no blending, which is how gradient-based stripes and progress bars are built. And bunching several stops close together concentrates the transition in a narrow band, leaving broad flat areas either side.
A gradient between two very different hues will pass through muddy intermediate colours. Adding a stop in the middle at a colour you actually want steers it through better territory.
What this generator does not output
A few things are worth knowing before you paste the result into production CSS.
- No vendor prefixes. Modern browsers have not needed
-webkit- or -moz- gradient prefixes for years, but if you support very old browsers you will need to add them yourself.
- No solid-colour fallback. Adding a plain
background-color before the gradient line is good practice for anywhere the gradient does not render, and for readable text if it fails.
- No transparency. Colours come from the browser's colour input, which is opaque six-digit hex. For a fade-to-transparent effect, edit the copied CSS by hand to use
rgba().
- Radial gradients are always circles. There is no ellipse, size or position control here — edit the copied declaration if you need
ellipse at top left.
- Conic gradients always start at 0deg. Change
from 0deg in the copied CSS to rotate the sweep.
Keeping text readable on a gradient
Text over a gradient has to stay legible across the whole span, not just where you happened to check. A white heading that reads well over the dark end of a gradient can fail badly over the light end.
Check contrast against the lightest and darkest points of the gradient behind the text, and keep the range narrow where text sits. A semi-transparent overlay between the gradient and the text is the usual fix when the range has to stay wide.