CSS Gradients Guide: Linear, Radial and Conic Syntax
A CSS gradient guide with copyable examples: linear, radial and conic syntax, color stops, hard edges, and how to pick gradient colors that blend cleanly.
Updated
A CSS gradient is an image the browser draws from a list of colors, set with background or background-image. The three types are linear-gradient() for a straight-line blend, radial-gradient() for a blend that spreads from a center point, and conic-gradient() for a blend that sweeps around a center like a clock hand. The shortest working example is background: linear-gradient(#7c3aed, #22d3ee);.
Because a gradient is an image and not a color, it does not work in background-color or color. Everything below goes in background or background-image.
Linear gradient syntax
The pattern is linear-gradient(direction, color-stop, color-stop, ...).
linear-gradient(#7c3aed, #22d3ee): no direction, so it runs top to bottom.linear-gradient(to right, #7c3aed, #22d3ee): left to right.linear-gradient(to bottom right, #7c3aed, #22d3ee): corner to corner.linear-gradient(135deg, #7c3aed, #22d3ee): an exact angle.
Angles start at 0deg pointing up and increase clockwise.
| Angle | Keyword | Runs toward |
|---|---|---|
0deg | to top | Top |
90deg | to right | Right |
180deg | to bottom | Bottom (the default) |
270deg | to left | Left |
45deg | none | Up and to the right |
135deg | none | Down and to the right |
A corner keyword and a 45 degree angle are only the same thing on a square. On a wide box, to bottom right aims at the actual corner, while 135deg keeps a fixed angle.
Color stops
Each color can carry a position, as a percentage or a length. Without positions, colors are spaced evenly.
- Three evenly spaced colors:
linear-gradient(90deg, #7c3aed, #ec4899, #f97316) - Explicit positions:
linear-gradient(90deg, #7c3aed 0%, #ec4899 30%, #f97316 100%). The pink now arrives early, and the long stretch to orange takes up the rest. - A hard edge:
linear-gradient(90deg, #7c3aed 50%, #22d3ee 50%). Two stops at the same position leave no room to blend, so you get two solid halves. - Two positions on one color:
linear-gradient(90deg, #7c3aed 0% 50%, #22d3ee 50% 100%). Same result, written as a range per color. - A color hint:
linear-gradient(90deg, #7c3aed, 30%, #22d3ee). The bare percentage moves the midpoint of the blend to 30 percent without adding a color.
Hard edges are how striped and segmented backgrounds are made without any image file.
Radial gradient syntax
The pattern is radial-gradient(shape size at position, color-stops). Every part before the colors is optional. The defaults are an ellipse that matches the box proportions, sized to reach the farthest corner, centered.
radial-gradient(#7c3aed, #22d3ee): an ellipse from the center.radial-gradient(circle, #7c3aed, #22d3ee): a true circle.radial-gradient(circle at top left, #7c3aed, #22d3ee): a circle that starts in the corner.radial-gradient(circle closest-side at 30% 40%, #7c3aed, transparent): a spot that fades out when it reaches the nearest edge.
The size keywords are closest-side, farthest-side, closest-corner and farthest-corner. A radial gradient fading to transparent, layered over a dark background color, is the standard way to make a soft glow.
Conic gradient syntax
The pattern is conic-gradient(from angle at position, color-stops). Colors change as you go around the center, starting at the top and moving clockwise. Stop positions can be percentages or angles.
- A color wheel:
conic-gradient(red, yellow, lime, aqua, blue, magenta, red). Repeating the first color at the end hides the seam. - A pie chart:
conic-gradient(#7c3aed 0% 40%, #22d3ee 40% 75%, #e5e7eb 75% 100%)withborder-radius: 50%on the element. - A rotated start:
conic-gradient(from 90deg, #7c3aed, #22d3ee).
Conic gradients work in all current browsers.
Repeating and layered gradients
Each type has a repeating version: repeating-linear-gradient(), repeating-radial-gradient() and repeating-conic-gradient(). The stop list tiles once it ends. Diagonal stripes are repeating-linear-gradient(45deg, #7c3aed 0 10px, #22d3ee 10px 20px).
background also accepts several gradients separated by commas. The first one listed sits on top, so the upper layers need transparency for the lower ones to show.
Choosing gradient colors
Not every pair of colors blends well. The browser interpolates in sRGB by default, which draws a straight line between the two colors. If they sit on opposite sides of the color wheel, that line passes through gray and the middle of the gradient looks washed out.
Three ways to avoid it:
- Pick neighbors. Colors within roughly a quarter turn of each other on the wheel, such as blue to purple or orange to pink, blend cleanly.
- Add a middle stop. Going from blue to yellow through a green or pink stop steers the blend around the gray.
- Change the interpolation space.
linear-gradient(in oklch, #7c3aed, #f97316)blends through vivid hues instead of gray. This syntax works in current versions of the major browsers but not in older ones, so put a plain gradient on the line before it as a fallback.
Some pairs that work as a starting point:
| Mood | From | To |
|---|---|---|
| Violet to cyan | #7c3aed | #22d3ee |
| Sunset | #f97316 | #ec4899 |
| Ocean | #0ea5e9 | #1e3a8a |
| Mint | #34d399 | #06b6d4 |
| Soft peach | #fda4af | #fde68a |
| Night | #0f172a | #4338ca |
If you have one brand color and need a partner for it, the Color Palette Generator lists analogous colors, which are the neighbors that blend well, from a single HEX value.
Common uses
- Gradient text: set
background: linear-gradient(90deg, #7c3aed, #22d3ee), thenbackground-clip: text(plus-webkit-background-clip: text) andcolor: transparent. - Image overlay:
linear-gradient(to top, rgb(0 0 0 / 70%), transparent)layered above a photo keeps white captions readable. Check the result against the rules in WCAG color contrast explained. - Buttons: a shallow two-stop gradient with stops only 5 to 10 percent apart in lightness adds depth without looking dated.
Building one visually
Writing stops by hand is slow because you cannot see the result. The Gradient Generator shows a live preview while you edit. It builds linear and radial gradients with two to five color stops, each with its own color and position. Linear gradients take one of eight direction presets or a custom angle. The output is available as a CSS background line, as Tailwind classes, or as SVG markup with a matching gradient definition.
Two limits to know. The radial output is a centered circle, so for an off-center or elliptical gradient, edit the generated line using the syntax above. Conic and repeating gradients are not generated, so write those by hand. Tailwind's built-in gradient classes cover three stops and the eight standard directions, and the Tailwind tab notes when a design goes beyond that.
Other color tools, including contrast checking and format conversion, are in the colors category.
Try it
Open the Gradient Generator, set the direction to 135deg, and replace the two default stops with a pair from the table above. Add a third stop in the middle, drag its position, and copy the CSS line when the preview looks right.