First CHToolsFree web tools

FIRST CH TOOLS / DESIGN / 44 CSS GRADIENT GENERATOR

CSS Gradient Generator

Build linear, radial and conic gradients by dragging the stops, and copy the CSS. Choose OKLCH interpolation (in oklch) and the middle of two saturated colours stops turning grey. An sRGB fallback line for older browsers comes out at the same time.

Pick a type and a direction

Colour stops (drag a handle, double-click the bar to add)

Colours can be written as #c8501f, rgb(200 80 31 / 0.5), hsl(14 73% 45%), oklch(56% 0.16 40) or a CSS name such as tomato. Handles also move with the arrow keys (Shift for 10% steps, Delete to remove).

Preview
2
Colour stops
135deg
Direction / centre
oklch
Interpolation space
0
CSS length (characters)
Generated CSS

  
Checks

    Converting one colour (HEX ⇄ RGB ⇄ HSL ⇄ OKLCH, alpha flattening) is in the Color Converter. Legibility of text over a background is in the Contrast Checker, and sizes that follow the viewport are in the CSS clamp() Calculator.

    An OKLCH gradient against the sRGB default, measured

    The reason to reach for an OKLCH gradient is the middle. CSS interpolates sRGB numbers unless told otherwise, and between two saturated colours far apart in hue that straight line passes close to neutral. Below is one blue-to-yellow gradient — #0066ff to #ffcc00, 90deg — built three ways by this page. The bars are the real declarations; the colour under each is what this tool bakes at the 50% mark when it writes the sRGB fallback.

    Default (sRGB) — middle #809980
    in oklab — middle #8ea7b7
    in oklch — middle #00ca9d
    InterpolationColour at 50%Chroma there (OKLCH C)
    Default, i.e. in srgb#8099800.046
    in oklab#8ea7b70.036
    in oklch#00ca9d0.149
    The two ends, for comparison#0066ff / #ffcc000.241 / 0.177

    That is the grey band, as a number. The ends carry a chroma of 0.241 and 0.177, and sRGB interpolation drops the halfway point to 0.046 — about a fifth of what the ends have. in oklch holds 0.149 there, so the gradient stays a colour all the way across instead of sagging through grey. (Chroma values read from the Color Converter; the 50% colours are this page's own fallback output, so you can reproduce every row by switching the Interpolation select above.)

    in oklab is not the fix for this pair — and that is not a bug. OKLab keeps rectangular coordinates, so it travels the straight line between the two colours; blue and yellow sit on roughly opposite sides of the neutral axis, so that line runs through it and the middle comes out flatter than sRGB. OKLCH is the polar form, so the same pair travels around the hue circle — blue, teal, green, yellow — which is where the colourfulness in the middle comes from. Choose oklab when you specifically do not want that hue detour (two tints of one hue, or a fade to white or black), and oklch the rest of the time.

    Linear, radial and conic gradients in OKLCH

    The interpolation method goes in the first argument, next to the angle or the position, not with the colour stops. These are the three forms this generator writes:

    /* linear */
    background-image: linear-gradient(90deg in oklch, #0066ff 0%, #ffcc00 100%);
    
    /* radial */
    background-image: radial-gradient(ellipse farthest-corner at 50% 50% in oklch, #0066ff 0%, #ffcc00 100%);
    
    /* conic */
    background-image: conic-gradient(from 0deg at 50% 50% in oklch, #0066ff 0%, #ffcc00 100%);
    
    /* the colour wheel: one colour at both ends, the long way round the hue circle */
    background-image: linear-gradient(90deg in oklch longer hue, #c8501f 0%, #c8501f 100%);

    A browser that cannot read in oklch throws the whole declaration away, so ship the sRGB line first and the OKLCH line second — the tool above writes both, with the intermediate colours baked in along the same curve. The browser versions this needs are under How it works.

    How to Use

    1. Pick a type and directionChoose linear, radial or conic, then set the angle (or the centre). The arrow buttons drop in 0deg through 315deg.
    2. Place the coloursDrag a handle along the bar to move a stop, and use the swatch or the text field in its row to change the colour. Double-click the bar to add a stop where you clicked.
    3. Copy and paste"Copy value" gives you the bare linear-gradient(…); "Copy declaration" gives all three lines including the fallback.

    About This Tool

    A gradient is nothing more than which colour sits where. This page lets you lay out those pairs — a position from 0 to 100% and a colour — and assembles them into linear-gradient, radial-gradient or conic-gradient CSS. Handles drag, double-clicking adds, and buttons distribute or reverse the stops, so the shape is decided without typing numbers. The angle comes from a slider or from the eight direction buttons.

    OKLCH interpolation is the default here. CSS mixes sRGB numbers unless you say otherwise, which leaves a grey middle between two saturated colours of different hue. Adding in oklch interpolates in a perceptually even space, holding lightness and colourfulness steady all the way across. You can also choose which way round the hue circle to travel (shorter or longer) — a conic gradient with longer hue draws the colour wheel.

    The fallback for older browsers comes out with it. A browser that cannot read the interpolation method throws the whole declaration away, so the tool writes a first line in which intermediate colours are baked in as ordinary sRGB stops along the same curve, followed by the real in oklch version. The baking follows CSS Color 4 colour interpolation: components are premultiplied by alpha before mixing and the hue is corrected for the chosen direction, so semi-transparent stops stay clean.

    It pairs with /color/ for single colours. HEX ⇄ RGB ⇄ HSL ⇄ OKLCH conversion, alpha flattening and tone palettes live in the Color Converter & Alpha Calculator; this page arranges the colours you settled on there into a gradient. Everything runs in the browser and nothing is uploaded. Directly callable via URL parameters: /en/gradient/?type=linear&angle=135&space=oklch&stops=%23c8501f@0|%2323282e@100

    Other Tools