Skip to content

CSS Gradient Generator

Build linear, radial and conic gradients with a live preview and copy the background CSS. OKLCH interpolation adds a fallback line for older browsers.

Presets

Type
deg

Color stops

Click the bar to add a stop there, and drag a handle to move it. With the keyboard, arrow keys move a stop by 1% (10% with Shift), and Delete removes it.

%
%

CSS

background: linear-gradient(90deg, #ff7e5f 0%, #feb47b 100%);

What you enter is processed only in this browser and is never sent to a server. How it works

A CSS gradient blending three color stops with a color adjustment bar

This tool lets you build a gradient while watching its colors and direction in a preview, then copy the finished background declaration. It opens with the “Sunset” preset, whose CSS is background: linear-gradient(90deg, #ff7e5f 0%, #feb47b 100%);.

How to use it

  1. Presets: click one of the five, Sunset, Ocean, Candy, Monochrome or Aurora, as a starting point.
  2. Type: choose “Linear”, “Radial” or “Conic”. The options underneath depend on the type.
  3. Color stops: set the colors and their positions. The next section covers the controls in detail.
  4. Interpolate in OKLCH (in oklch): when on, the colors are joined through the OKLCH color space.
  5. CSS: shows the declaration for the current settings. “Copy CSS” copies it.
Type CSS function Options you can set
Linear linear-gradient Angle. 90deg runs left to right and 180deg runs top to bottom
Radial radial-gradient Shape (“Circle” or “Ellipse”) and Center position
Conic conic-gradient Angle (the direction the colors start sweeping from) and Center position

Set the angle by typing in the number field or by moving the slider between 0 and 360. The number field also accepts values above 360 and negative values, and they go into the CSS as entered. Center position offers nine choices: the center, the four sides and the four corners.

Working with stops

A color stop is a point that says “this color at this position”, and the gradient is made by joining the stops. You can have from 2 to 8.

  • Click an empty spot on the Gradient bar and a stop appears there. It takes the color that was already showing at that spot, so the gradient looks the same right after you add it. Drag it or change its color from there.
  • The “Add stop” button inserts a white (#ffffff) stop halfway between the last stop and 100%. If the last stop is already at 100%, the new one goes in the middle of the widest gap between stops so that it doesn’t land on top of it. With one stop at 0% and one at 100%, it appears at 50%.
  • Drag a handle, or type a number into the position field in the list, to change a position. On the keyboard, the arrow keys move a focused handle by 1%, or by 10% with Shift held, and Delete removes it.
  • The Move up and Move down buttons in the list swap a stop’s position with its neighbor’s. Use them to reverse the order of colors.
  • Remove is available only when there are 3 or more stops.

The list is always shown sorted by position, and the stops go into the CSS in that order too. Positions are written to one decimal place.

Accepted color inputs: Stop colors are read as HEX (3, 4, 6 or 8 digits), color names, rgb(), hsl(), oklch() and transparent. The hwb(), lab(), lch() and color() functions and variables written with var() are not read. A color that can’t be read gets the message “This isn’t a CSS color this tool can read.”, and that stop is left out of the preview and the CSS. Colors that are read go into the CSS exactly as you typed them.

Interpolating in OKLCH changes the colors in between

Unless told otherwise, a CSS gradient whose stops are all written as HEX, color names, rgb() or hsl() works in the sRGB color space and blends the red, green and blue values of two colors in a straight line, each on its own. Those numbers aren’t proportional to the brightness people perceive, so blending two colors that sit far apart on the color wheel makes the middle dark and dull. OKLCH handles lightness (L), chroma (C) and hue angle (H) separately and carries each one across, so lightness and chroma don’t sag in the middle.

Here is the color at the 50% point of the bar, calculated with two stops at 0% and 100%.

The two colors Midpoint blended in sRGB Midpoint blended in OKLCH
Red #ff0000 → green #00ff00 #808000 (dark olive) #f99500 (bright orange)
Blue #0000ff → yellow #ffff00 #808080 (gray) #00cfbd (teal)
Sunset preset #ff7e5f → #feb47b #ff996d #ff9a68

The further apart the hues, the bigger the difference, and with similar colors like the Sunset preset there is next to none. Keep in mind, too, that blending in OKLCH brings hues into the middle that neither color has. The orange and yellow that pass between red and green are an example. If you want the two colors to blend straight into each other, leave the option off.

Why the copied CSS has two lines

Syntax that names an interpolation method, such as in oklch, came to CSS fairly late, and some browsers don’t understand it. That is why turning OKLCH interpolation on gives you two declarations. For a linear gradient from red to green they look like this.

background: linear-gradient(90deg, #ff0000 0%, #ff3300 12.5%, #ff5600 25%, #ff7600 37.5%, #f99500 50%, #e3b200 62.5%, #c2ce00 75%, #8fe800 87.5%, #00ff00 100%);
background: linear-gradient(90deg in oklch, #ff0000 0%, #00ff00 100%);
  • The first line is the fallback. The gap between each pair of neighboring stops is divided into 8 equal steps, and the 7 in-between colors, calculated in OKLCH, are inserted as ordinary HEX stops. Two stops become 9, and three become 17.
  • The second line is the in oklch syntax itself.

When a property is declared twice the later one applies, so a browser that knows in oklch uses the second line, and one that doesn’t ignores the second line and uses the first.

While OKLCH interpolation is on, the preview and the gradient bar on this page are drawn the first-line way in every browser. The fallback line is an approximation, with its in-between colors written as HEX within the sRGB range, so it can differ slightly from what a browser draws from the second line directly. If the exact colors matter, check the result in your target browsers after pasting.

What this tool can’t make

  • Repeating gradients such as repeating-linear-gradient. You have to add repeating- in front of the function name in the copied CSS and adjust the stop range by hand.
  • A size for radial gradients (closest-side and the like), or a center position given as coordinates such as at 30% 70%
  • Backgrounds that layer several gradients separated by commas
  • Stop positions in px instead of percentages
  • Other interpolation methods such as in hsl or in oklab

Sources

Frequently asked questions

I clicked a preset and the OKLCH interpolation I had turned on went off.

A preset doesn't only change the colors. It sets the type, angle, shape, center position and stops all at once, and it also turns "Interpolate in OKLCH (in oklch)" off. Any stops you made yourself are replaced by the preset's stops and can't be brought back. If you want to start from a preset, pick the preset first and switch the option on afterwards.

Can I make hard-edged stripes where two colors don't blend?

Yes, by putting two stops at the same position. Place red at 0% and 50% and blue at 50% and 100% and you get linear-gradient(90deg, #ff0000 0%, #ff0000 50%, #0000ff 50%, #0000ff 100%), where the color changes abruptly in the middle. Typing the same number into the position fields is more precise than dragging the handles.

If a gradient fades to transparent, won't the middle go dark when I interpolate in OKLCH?

It won't. Internally, transparent is a transparent black, and blending toward it naively turns the middle murky. This tool multiplies by alpha before blending, the same way CSS gradients do. Look at the fallback line for a gradient from red (#ff0000) to transparent: the in-between stops are #ff0000bf, #ff000080 and #ff000040. The red stays put and only the opacity drops.

Can I add the copied CSS to an element that already has a background?

Paste the copied CSS below the existing background declaration within the same rule. If another rule overrides the background, check selector specificity and !important as well. If OKLCH interpolation produces two lines, paste both and keep their order.

Open-source software used: culori (MIT)

Last updated: