Linear, radial and conic gradients — the syntax, the gotchas, and gradient text.
CSS has three gradient functions, each used as a background-image value:
linear-gradient() — colors transition along a straight line at a given
angle. The most common gradient type, used for buttons, hero backgrounds, and overlays.radial-gradient() — colors radiate outward from a center point, like a
spotlight or a glow.conic-gradient() — colors sweep around a center point like a color
wheel or pie chart, rather than radiating outward.background: linear-gradient(90deg, #6366f1, #a855f7);
/* or with a direction keyword instead of degrees */
background: linear-gradient(to right, #6366f1, #a855f7);
The first argument is the direction — either an angle (0deg points up, and angles increase
clockwise) or a to <side> keyword. Every argument after that is a color stop, applied in
order along that line.
You can add as many color stops as you like, and optionally pin each one to an explicit position:
background: linear-gradient(90deg, #6366f1 0%, #a855f7 50%, #ec4899 100%);
Without explicit positions, stops are spaced evenly. Stop positions must increase left-to-right in the list — an out-of-order position is clamped up to the previous stop's value, which is a common source of a gradient that doesn't look like what you expected.
background: radial-gradient(circle, #6366f1, #1e1b4b);
background: conic-gradient(from 0deg, red, yellow, lime, aqua, blue, magenta, red);
radial-gradient() defaults to an ellipse matching the element's aspect ratio; add the
circle keyword to force a perfect circle. conic-gradient() is the natural choice
for pie-chart-style visualizations or hue-wheel color pickers.
To apply a gradient to text instead of a background box:
.gradient-text {
background: linear-gradient(90deg, #6366f1, #00d4aa);
background-clip: text;
-webkit-background-clip: text;
color: transparent;
}
The gradient still renders as a background image; background-clip: text clips it to the
shape of the text glyphs, and color: transparent lets that clipped background show through
instead of a solid text color.
-webkit-background-clip breaks gradient text in Safari.linear-gradient transitions colors along a straight line at a given angle; radial-gradient radiates colors outward from a center point, like a spotlight or glow.
Place two color stops at the exact same position — the gradient jumps instantly from one color to the next at that point instead of blending.
Safari requires the -webkit-background-clip: text prefix alongside the unprefixed background-clip: text property — without it, the text stays its default color instead of showing the gradient.
Not the gradient function itself directly, but you can animate background-position on an oversized gradient background, or crossfade between two gradient layers with opacity, to fake a smooth gradient animation.