EN

Linear Gradient CSS: Syntax, Angles, Radial and Conic Gradients

A soft violet to pink to amber gradient sweeping across an abstract designer desk with a ruler and paint swatches

Quick Answer

A CSS gradient is an image the browser draws for you, so you write a short function instead of exporting a file. `linear-gradient(135deg, #6D46D3, #EC4899)` blends two colors along a line at 135 degrees. `radial-gradient()` spreads color outward from a point, and `conic-gradient()` sweeps it around a point. All three work anywhere CSS accepts an image, such as `background-image`.

On this page
  1. What does linear-gradient() do and how do angles work?
  2. How do color stops and hard stops work?
  3. How do radial and conic gradients differ?
  4. How do repeating gradients and layered backgrounds work?
  5. Which browsers support CSS gradients, and do you need a fallback?
  6. How do you keep text readable over a gradient?
  7. Frequently Asked Questions
  8. Our Take
  9. Sources

Key Takeaways

  • A gradient is an `<image>`, so use it in `background` or `background-image`, never in `background-color`.
  • In `linear-gradient()`, `0deg` points up and angles grow clockwise; `to right` equals `90deg`.
  • Two color stops at the same position make a hard edge, which is how stripes and pie charts are built.
  • Radial gradients default to an ellipse sized to the farthest corner; conic gradients start at 12 o'clock and turn clockwise.
  • Text over a gradient has to be checked at its worst spot, not at the average color.

What does linear-gradient() do and how do angles work?

linear-gradient() draws a straight line through the box, the gradient line, and colors every point by where it falls along that line. In CSS Images Level 3, 0% sits at the starting point and 100% at the ending point [1]. You pick the direction with an angle or with to keywords.

.hero {
  background: linear-gradient(135deg, #6D46D3, #EC4899);
}

MDN states that 0deg is the same as to top, and larger angles rotate clockwise from there [3]. The same page lists to top, to right, to bottom and to left as 0deg, 90deg, 180deg and 270deg. If you give no direction at all, the default is to bottom.

How linear-gradient angles map to directions A square filled with a violet to pink gradient. Labels around it show 0deg is up, 90deg is right, 180deg is down and 270deg is left. A white arrow draws from the top left toward the bottom right to show the 135deg gradient line. 0deg, to top 90deg, to right 180deg, to bottom 270deg, to left white arrow: linear-gradient(135deg, ...)
Angles in linear-gradient() rotate clockwise from up. The white arrow is the gradient line of 135deg.

Corner keywords such as to bottom right work too. Pick the angle form when you want an exact tilt, and the keyword form when you want the gradient to follow the box as it resizes. The gradient generator lets you drag the angle and watch the string change.

A note on spelling: UK readers search for "colour gradient", and the CSS is identical. The property names stay in US spelling, so color is always color.

How do color stops and hard stops work?

A color stop is a color plus an optional position, written as a percentage or a length. If you skip positions, MDN explains that the browser places unpositioned stops halfway between their neighbors, so these two lines are equivalent:

background: linear-gradient(#6D46D3, #EC4899, #F59E0B);
background: linear-gradient(#6D46D3 0%, #EC4899 50%, #F59E0B 100%);

That evenly spaced behavior is described on the MDN linear-gradient page [3]. Here are the three colors used in this guide, with every value computed by the SwatchNest color core. HSL values are rounded to whole numbers.

Name in this guideHEXRGBHSLWhite text on itInk #17172F text on it
Violet#6D46D3rgb(109 70 211)hsl(257 62% 55%)6.05:12.88:1
Pink#EC4899rgb(236 72 153)hsl(330 81% 60%)3.52:14.96:1
Amber#F59E0Brgb(245 158 11)hsl(38 92% 50%)2.14:18.14:1

The HEX to RGB converter and the color converter give you these same conversions for any color you pick.

How do you make a hard stop?

When two stops share the same position, the transition becomes a hard line between them. MDN says that if two or more color stops are at the same location, the transition is a hard line between the first and last colors declared there [3]. It also supports a two-position shorthand:

/* A sharp split down the middle */
background: linear-gradient(90deg, #6D46D3 0 50%, #EC4899 50% 100%);
Smooth stops compared with a hard stop Two horizontal bars on a 0 to 100 percent scale. The top bar blends violet into pink across its whole width. The bottom bar switches from violet to pink at exactly 50 percent. A marker slides along the bottom bar and stops at the 50 percent hard edge. Smooth: #6D46D3 0%, #EC4899 100% Hard: #6D46D3 0 50%, #EC4899 50% 100% 0%25%50%75%100%
Stop positions on a 0 to 100 percent scale: one smooth blend, one hard stop at 50%.

Out-of-order stops behave the same way. CSS Images 3 says that a stop positioned earlier than a stop before it is moved to the largest position seen so far, which also produces a hard edge [1].

A color hint is a bare percentage between two stops. It moves the midpoint of the blend without adding a color. MDN's example, linear-gradient(red 10%, 30%, blue 90%), keeps solid red until 10%, solid blue from 90%, and puts the halfway point of the blend at 30% instead of 50%. Hints are handy when a gradient looks like it spends too long on one color.

How do radial and conic gradients differ?

Linear gradients change along one line. Radial gradients change with distance from a point, and conic gradients change with the angle around a point.

Linear, radial and conic gradients side by side Three squares appear one after another. The linear square blends violet, pink and amber along a diagonal line. The radial square blends outward from the center. The conic square, drawn here as 24 small wedges, sweeps around its center starting at the top. linear along a line 135deg radial out from a center circle at 50% 50% conic around a center from 0deg
The same three colors drawn with each gradient type. The conic square is approximated with 24 flat wedges.

What are radial gradients?

The MDN syntax is radial-gradient([shape] [size] [at position], stops). The shape is circle or ellipse, and ellipse is the default. The size defaults to farthest-corner, and the center defaults to center [4]. Position 0% is the center, and 100% is where the ending shape meets the gradient ray.

.spotlight {
  background: radial-gradient(circle at 30% 20%, #F59E0B 0%, #EC4899 50%, #6D46D3 100%);
}

Move the center with at to fake a light source. The size keywords closest-side, closest-corner, farthest-side and farthest-corner control how large the ending shape is. For soft glows behind a card, closest-side keeps the blend inside the box.

What are conic gradients?

The MDN syntax for conic-gradient() is conic-gradient([from angle] [at position], stops). The gradient starts at north (12 o'clock) and moves clockwise, from rotates it clockwise by the angle you give, and at sets the center [5]. Stops use angles (browsers also accept percentages, but MDN notes that is not part of the specification), and if the first has no angle it is 0deg, while a last stop without one is 360deg.

.wheel {
  background: conic-gradient(from 0deg at 50% 50%, #6D46D3 0deg, #EC4899 180deg, #F59E0B 360deg);
  border-radius: 50%;
}

/* Hard stops turn it into a pie chart */
.pie {
  background: conic-gradient(#6D46D3 0 144deg, #EC4899 144deg 270deg, #F59E0B 270deg);
  border-radius: 50%;
}

MDN also warns that pie charts made from background gradients are not accessible, because CSS images have no alternative text. If the chart carries real information, describe it in the page text as well. You can copy ready-made strings from the gradient generator, which writes linear, radial and conic CSS.

How do repeating gradients and layered backgrounds work?

Each function has a repeating twin: repeating-linear-gradient(), repeating-radial-gradient() and repeating-conic-gradient(). MDN explains that the repeat length is the distance between the first and last color stops, so the last stop's position sets the period [6]. If the last stop is left unspecified, it defaults to 100% and nothing repeats.

.stripes {
  background: repeating-linear-gradient(
    -45deg,
    #F1ECFD 0 20px,
    #6D46D3 20px 40px
  );
}

That gives 40 pixel diagonal stripes. Because #F1ECFD and #6D46D3 differ, each repeat starts with a hard edge, which is what you want for stripes.

Can you stack more than one gradient?

Yes. Multiple backgrounds are a comma-separated list, with the first one on top and the last one at the back, and only the last layer can include a background color [7]. A semi-transparent gradient on top of a solid one gives depth without an image file:

.card {
  background:
    radial-gradient(circle at 80% 0%, rgb(245 158 11 / 55%), transparent 60%),
    linear-gradient(135deg, #6D46D3, #EC4899);
}

The top layer fades from amber to transparent, so the linear gradient shows through. For ready-made inspiration, browse the gradient collection, the sunset gradients or the purple gradients.

Two habits keep gradient CSS easy to maintain. First, write angles and positions explicitly, such as 135deg and 0% and 100%, so the next person can read the intent without guessing defaults. Second, store the stops as custom properties, for example --brand-start: #6D46D3; and --brand-end: #EC4899;, then reuse them in linear-gradient(135deg, var(--brand-start), var(--brand-end)). When the brand color changes, every gradient follows. If you need new color pairs, the palette generator builds harmonious sets, and the color converter turns any of them into RGB or HSL.

Which browsers support CSS gradients, and do you need a fallback?

MDN lists linear-gradient() and radial-gradient() as Baseline "widely available," supported across browsers since July 2015, and conic-gradient() since November 2020 [3] [5]. MDN adds that some parts of each feature can have varying levels of support, so check its compatibility table before relying on newer options.

For the basic functions, a fallback is a cheap safety net rather than a necessity. Declare a solid color first, then the gradient. A browser that cannot parse the second line keeps the first:

.banner {
  background: #6D46D3;
  background: linear-gradient(135deg, #6D46D3 0%, #EC4899 100%);
}

This is the exact pattern the SwatchNest generator copies out. Remember that a gradient is an image, so it never works in background-color.

How do you keep text readable over a gradient?

WCAG 2.2 success criterion 1.4.3 asks for at least 4.5:1 for normal text and 3:1 for large text, defined as 18 point or 14 point bold [2]. That page lists background images without enough contrast as a failure, and it gives no special testing method for gradients. A practical approach, and our advice rather than a W3C rule, is to measure against the worst color the text sits on.

Take white text on our violet to pink gradient. At the violet end it scores 6.05:1, which passes. At the pink end it scores 3.52:1, which fails for body text and passes only as large text. On amber it drops to 2.14:1. One way to fix this is to lay a dark scrim over the gradient, using the layering trick from above.

.hero {
  color: #FFFFFF;
  background:
    linear-gradient(rgb(23 23 47 / 55%), rgb(23 23 47 / 55%)),
    linear-gradient(135deg, #6D46D3, #EC4899, #F59E0B);
}

With a 55% ink #17172F scrim, we computed white text at 11.40:1 over violet, 9.03:1 over pink and 6.70:1 over amber, all above 4.5:1. Always confirm with the contrast checker. Our guide to what a good contrast ratio is explains the formula, and the palette generator helps you pick stops that already work together.

Frequently Asked Questions

Can I use a gradient in background-color?

No. MDN says a gradient is an <image>, so it cannot be used on background-color or other <color> properties. Use background or background-image instead.

How do I move the middle of a blend without adding a color?

Add a color hint, a bare percentage between two stops. In MDN's example, linear-gradient(red 10%, 30%, blue 90%) puts the halfway point of the red to blue blend at 30% instead of 50%.

Is `to right` the same as `90deg`?

Yes. MDN lists to right as equivalent to 90deg, to top as 0deg, to bottom as 180deg and to left as 270deg.

Our Take

We think most gradients on the web are better when they are quieter. Two or three nearby colors, a slight diagonal such as 135deg, and a solid fallback line cover almost every hero, button and card. We would reach for hard stops and conic gradients only when they show real information, and we would always pair white text with a dark scrim instead of trusting the average color. If a gradient makes you squint, the design is telling you something, so simplify it. Treat every number here as a starting point and run your own colors through the tools before they ship.

Sources

  1. CSS Images Module Level 3. W3C, 2023.
  2. Understanding Success Criterion 1.4.3: Contrast (Minimum). W3C.
  3. linear-gradient(). MDN Web Docs, 2026.
  4. radial-gradient(). MDN Web Docs, 2026.
  5. conic-gradient(). MDN Web Docs, 2026.
  6. repeating-linear-gradient(). MDN Web Docs, 2026.
  7. Using multiple backgrounds. MDN Web Docs, 2026.

Color values are shown in sRGB. Contrast results follow WCAG 2.x and do not cover every accessibility need. Spotted an error? Tell us.