Perceptual Gradient Generator (OKLCH, OKLab, CSS)
Build smooth multi-stop CSS gradients in OKLab or OKLCH, with a fallback for every browser.
How it works
Enter 2–16 color stops in any CSS color syntax. Get a modern CSS gradient that interpolates in OKLab, OKLCH, Lab, LCH or linear light, a fallback with dense HEX stops and its measured error, evenly spaced palette steps and an optional bilinear mesh gradient as PNG.
- Parse each stop with CSS Color 4 syntax and fix positions like CSS Images 3: the first and last stop default to 0 % and 100 %, a position smaller than an earlier one is raised to it, and stops without a position are spaced evenly between their neighbours.
- Interpolate between neighbouring stops in the chosen space (CSS Color 4 §12). In OKLCH and LCH the hue follows the chosen path; a grey stop has no hue and takes its neighbour's, so grey to blue never passes through red. Colors outside sRGB are brought back with the CSS Color 4 gamut mapping (chroma reduction in OKLCH).
- The modern rule uses the CSS syntax "in <space>" so the browser interpolates itself. The fallback samples the same gradient at the step count plus every original stop and lets the browser mix those HEX stops in sRGB; its largest deviation from the true gradient is reported as an OKLab distance × 100 over 513 samples (about 2 is barely visible).
- The mesh gradient puts the grid colors at the corners of equal cells and mixes them bilinearly (first across, then down) in the chosen space; the PNG is 480 × 320 pixels.
Sources
Part of Lumina
-
Lumina Photo editor & image toolkit
Bring out what you saw. A free photo studio, right in your browser.
Related tools
- OKLCH Palette & Tint Scale Generator – Build perceptually even tint scales and hue harmonies in OKLCH, gamut-mapped for CSS.
- Color Converter & Gamut Mapper (OKLCH, Lab, P3) – Convert any CSS color to HEX, RGB, HSL, Lab, LCH, OKLab, OKLCH and Display P3.
- Two-Color Ramp Mixer – Mix two colors into an sRGB or linear-light ramp for drawing and pixel art.
- Contrast Fixer: Nearest Accessible Color – Find the closest color that reaches WCAG 3:1, 4.5:1 or 7:1 contrast — and repair a palette.
How to use the Perceptual Gradient Generator
Build smooth CSS gradients in OKLCH or OKLab, see how far the sRGB fallback drifts, take palette steps and render a mesh gradient as PNG.
What it is for
A plain CSS gradient mixes colours in sRGB, the same space your HEX codes live in. That is quick, but it is not how we see colour: blue to yellow turns muddy grey in the middle, and black to white looks too dark for most of the way. Perceptual spaces such as OKLab and OKLCH fix that, and modern browsers can interpolate in them directly.
This tool takes 2–16 colour stops in any CSS syntax (HEX, names, rgb(), oklch(), lab() …) and gives you three things: a modern CSS rule that tells the browser which space to use, a fallback rule made of dense HEX stops for older browsers, and evenly spaced palette steps you can reuse as design tokens. It also measures how far the fallback drifts from the real gradient, so you know whether it is good enough.
It handles opaque colours only; alpha in a stop is ignored. It is the same engine Lumina uses, so results match the app.
Worked example
The first example goes from deep teal #164E63 to sand #EBC17E in OKLCH with the shorter hue path and 9 steps. The result:
2 stops interpolated in oklch; the sRGB fallback deviates by at most 0.32 (OKLab × 100).
The modern rule is linear-gradient(90deg in oklch shorter hue, #164E63 0%, #EBC17E 100%). The nine steps run #164E63, #17616B, #25736F, #3E846F, #5D936D, #7FA16B, #A3AD6B, #C8B870, #EBC17E — the middle stays green and lively instead of fading to grey.
Now try black to white in OKLab with only 3 steps. The middle step is #636363, the grey that looks halfway. The fallback, though, deviates by 14.69 and the tool warns you: with three stops the browser fills the gaps in sRGB again. Raising the steps to 17 brings the error down to 6.35.
For contrast, red to blue in plain sRGB gives #7F0080 in the middle and a fallback error of only 0.289 — the fallback is exact there because the browser mixes in sRGB anyway.
How to read the result
- Preview shows the sampled steps as one strip.
- Stops and Fallback max error are the key metrics. The error is the largest OKLab distance × 100 between the true gradient and what an older browser would draw. Around 2 is hard to see; above that, raise the step count.
- CSS holds both rules: the fallback first, the modern rule inside
@supports, so every browser picks the best it can render. - Palette steps lists the evenly spaced colours; you can also download them as a GIMP palette.
- With a mesh grid, you also get a 480 × 320 PNG.
Tips and common mistakes
- Positions are optional.
oklch(0.7 0.15 30) 0,rebeccapurple 40,#2E8B57 100puts the purple at 40 %. Missing positions are spaced evenly, and a position smaller than an earlier one is raised to it, as in CSS. - Two stops at the same position make a hard edge; the fallback keeps it hard.
- The hue path only matters in OKLCH and LCH. Longer goes the long way round the colour wheel — the second example uses it for a rainbow-like conic gradient.
- A grey stop has no hue, so grey to blue keeps blue's hue instead of passing through red.
- For a mesh, write one row of colours per line, 2–6 per row, with the same count in every row.
FAQ
Which browsers understand "in oklch"?
Current versions of the major browsers support interpolation spaces in gradients. Older ones ignore the rule inside @supports and use the fallback.
OKLab or OKLCH?
OKLab blends straight through the middle and can lose saturation between distant hues. OKLCH keeps chroma and walks around the hue circle, which suits colourful gradients.
Why are some colours slightly different from what I typed?
Colours outside sRGB, such as very vivid oklch() values, are brought back with the CSS gamut-mapping method, which lowers chroma until the colour fits.
Can I use the steps as a palette?
Yes. Download the GIMP palette, or paste the HEX list into Lumina's Palette Studio or the palette converter.
Guide last updated:
For scripts and AI agents
- JSON API:
POST https://luminagradientgenerator.usefulweb.app/api/v1/calculate(same calculation as this page) - Interface description: OpenAPI 3.1 · AI guide: llms.txt
- MCP server (Streamable HTTP):
https://luminagradientgenerator.usefulweb.app/mcp· tool namelumina_gradient_generator
Example request
curl -s -X POST https://luminagradientgenerator.usefulweb.app/api/v1/calculate \
-H 'content-type: application/json' \
-d '{"stops":"#164E63\n#EBC17E","space":"oklch","hue":"shorter","kind":"linear","angle":90,"steps":9,"mesh":""}'