CSS Gradient Generator

Pick colors, drag the stops, and copy the CSS gradient. Build a linear gradient at any angle or a radial one, with as many color stops as you need. The preview redraws on every slider move, so you see each change without reloading a page.

0° 90° 180° 270° 360°

CSS Output

1 Features

Linear & Radial

Linear gradients take an angle from 0 to 360 degrees. Radial gradients are drawn as a circle from the center, so the angle slider is disabled.

Multiple Stops

Add Stop appends another color, and each stop has its own position slider. The tool sorts stops by position before writing the CSS, so they never end up out of order.

2 Example CSS

Generated CSS

1
background: linear-gradient(90deg, #3b82f6 0%, #8b5cf6 100%);

3 Browser support

You do not need vendor prefixes. The output uses linear-gradient() and radial-gradient(), which browsers have supported unprefixed since around 2012, so the tool emits one plain background declaration.

How to use the CSS Gradient Generator tool

  1. Choose Linear or Radial under Type. Linear shows an Angle slider from 0 to 360 degrees. Radial gradients start from the center and ignore the angle.
  2. Adjust the Color Stops: click a swatch to open the color picker or type a HEX value, then drag the position slider to move that stop. Click Add Stop for another color, and the trash icon to remove one (two stops minimum).
  3. Try the four preset buttons above the preview for a quick starting palette, or click Random Gradient for a new angle and colors.
  4. The preview box updates live and the CSS appears in the output panel as a background declaration.
  5. Click Copy CSS in the toolbar, or the copy icon on the output panel, and paste the rule into your stylesheet.

How to write a CSS gradient by hand or generate one in code

CSS

/* Linear: angle first, then stops with optional positions */
.hero {
  background-image: linear-gradient(90deg, #ff7e5f 0%, #feb47b 100%);
}

/* Radial: shape and size, then stops */
.badge {
  background-image: radial-gradient(circle at center, #2e3192 0%, #1bffff 100%);
}

/* Gradient text */
.title {
  background-image: linear-gradient(135deg, #8e2de2, #4a00e0);
  -webkit-background-clip: text;
  background-clip: text;
  color: transparent;
}

/* Hard stripe: two stops at the same position */
.stripe {
  background-image: linear-gradient(90deg, #5a3f37 50%, #2c7744 50%);
}

Use background-image rather than background if you also want to set a fallback background-color for old browsers.

JavaScript (browser)

const stops = [
  { color: "#ff7e5f", pos: 0 },
  { color: "#feb47b", pos: 100 },
];

function gradientCss(type, angle, stops) {
  const list = [...stops]
    .sort((a, b) => a.pos - b.pos)
    .map((s) => `${s.color} ${s.pos}%`)
    .join(", ");
  return type === "radial"
    ? `radial-gradient(circle, ${list})`
    : `linear-gradient(${angle}deg, ${list})`;
}

const css = gradientCss("linear", 90, stops);
console.log(css); // linear-gradient(90deg, #ff7e5f 0%, #feb47b 100%)

// Apply it in the browser
// document.querySelector(".hero").style.backgroundImage = css;

Sorting the stops by position matters: CSS clamps an out-of-order stop to the previous one and the color vanishes.

Python: generate evenly spaced stops

# Generate a smooth multi-stop gradient between two colors
def hex_to_rgb(h):
    h = h.lstrip("#")
    return tuple(int(h[i:i + 2], 16) for i in (0, 2, 4))

def mix(a, b, t):
    return tuple(round(x + (y - x) * t) for x, y in zip(a, b))

start, end, steps = hex_to_rgb("#2E3192"), hex_to_rgb("#1BFFFF"), 5
stops = []
for i in range(steps):
    r, g, b = mix(start, end, i / (steps - 1))
    stops.append(f"#{r:02x}{g:02x}{b:02x} {round(i * 100 / (steps - 1))}%")

print(f"background-image: linear-gradient(135deg, {', '.join(stops)});")

Use this in build scripts that emit palettes. The browser already interpolates between two stops, so extra stops only matter when you want a custom curve.

Common errors and how to fix them

The gradient does not show at all
The element has no height, or the rule was written as background-color, which only accepts a single color. Use background or background-image and make sure the element has size.
Gradient shows as a solid color
A later background-color or background shorthand overrides it, or all stops have the same position. Check the cascade in DevTools and space the stop positions out.
A color stop seems to be missing
Stops are given out of order, for example red 80%, blue 20%. CSS moves the second stop up to 80%, so blue never spreads. Sort the stops by position.
Gradient text is invisible or shows a rectangle
background-clip: text needs the -webkit- prefix in Chrome and Safari, plus color: transparent. Padding or display: inline-block changes can also break the clip; test in each browser.
Visible banding instead of a smooth blend
Long gradients between two similar colors show 8-bit steps. Add an intermediate stop, shorten the gradient, or overlay a subtle noise texture.

Good to know

A CSS gradient is an image with no intrinsic size. That explains most of its behavior: it belongs in background-image, it stacks with other images using commas, and it needs a sized element before it shows up. Angles run clockwise, 0deg up and 90deg right, so the CSS default of 180deg runs top to bottom.

Interpolate in oklch when the midpoint turns gray. Browsers blend in sRGB by default, and between complementary colors the middle goes muddy. CSS Color 4 lets you choose the interpolation space, for example linear-gradient(in oklch, red, blue), which keeps the middle vivid. Ship the plain syntax as the fallback and add the oklch version behind @supports.

Specifications and references

This tool follows the specifications below. Read them when you need the exact normative wording, for example to settle an edge case between two implementations.

Frequently Asked Questions

Which gradient types can I create?

Linear gradients at any angle from 0 to 360 degrees, and circular radial gradients from the center. Both take as many color stops as you add.

How do I add or remove color stops?

Click Add Stop to append a stop, then set its color and drag its position slider. Remove a stop with its trash icon. A gradient needs at least two stops, so the last two cannot be removed.

Is the generated CSS ready for production?

Yes. The output is a single background declaration using the standard linear-gradient() or radial-gradient() syntax, which every current browser reads without vendor prefixes.

Can I use the gradient on text?

Yes. Apply the gradient as background-image, then add background-clip: text (plus -webkit-background-clip: text for Safari and Chrome) and color: transparent to the element.

What does the Random button do?

Random Gradient picks a new angle and two random colors, and adds a third stop in the middle about half the time. Use it as a starting point, then adjust the stops.

Related

The color converter translates stops between HEX, RGB and HSL. The CSS formatter cleans up the rule once you paste it into your stylesheet.

More CSS & Design Tools

Browse all css & design tools

Copied to clipboard!