← All guides

CSS Gradients Explained: A Complete Guide

Linear, radial and conic gradients — the syntax, the gotchas, and gradient text.

The three gradient types

CSS has three gradient functions, each used as a background-image value:

linear-gradient() syntax

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.

Multi-stop gradients and explicit positions

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.

radial-gradient() and conic-gradient() basics

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.

Gradient text

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.

Common mistakes

Want to build this visually instead of hand-writing the CSS? Try the CSS Gradient Generator →

Frequently asked questions

What is the difference between linear-gradient and radial-gradient?

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.

How do I make a hard edge instead of a smooth blend in a gradient?

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.

Why is my gradient text not showing in Safari?

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.

Can I animate a CSS 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.