DevTools Logo

OKLCH Gamut Gradient & Harmony Studio

OKLCH Gamut Gradient Studio

Create perceptually smooth, gamut-aware gradients and color harmonies locally

Color inputs

About

Deterministic browser-only OKLCH color conversion and design studio with linear RGB and OKLab matrix transforms, chroma-reduction gamut mapping, shortest-path hue interpolation, CSS color(in oklch ...) output, and hexadecimal fallbacks.

Examples

Red to blue in five steps

Input
generateOklchGradient("#ff0000", "#0000ff", 5)
Output
{ length: 5, first: "#FF0000", last: "#0000FF" }

Endpoints are included verbatim and intermediate stops interpolate lightness, chroma, and shortest-path hue.

Complementary pair

Input
generateHarmony("#336699", "complementary")
Output
{ hues: [base.h, (base.h + 180) % 360] }

The second swatch sits exactly 180 degrees around the hue wheel from the base.

About this tool

OKLCH Gamut Gradient Studio builds perceptually uniform gradients with generateOklchGradient(start, end, steps): hex endpoints convert via hexToOklch, interpolate along the shortest hue path with interpolateOklch, and map back with oklchToHex so every stop is a displayable sRGB hex plus an oklch() CSS string.

Out-of-gamut colors are pulled into sRGB by mapToSrgbGamut, which binary-searches chroma downward while preserving lightness and hue — oklchToHex always returns an uppercase #RRGGBB fallback instead of clipping channels naively.

Harmonies come from generateHarmony(input, type) with fixed angles: complementary [0, 180], triadic [0, 120, 240], analogous [0, 30, -30]. All math is deterministic and client-side with no network calls.

How to use this tool

  1. Pick two endpoints

    Pass hex strings (or Oklch objects) plus a step count to generateOklchGradient — the first and last stops equal the inputs.

  2. Map wide-gamut colors

    Run mapToSrgbGamut on high-chroma picks to keep lightness and hue while shrinking chroma into sRGB.

  3. Add a harmony

    Call generateHarmony with complementary, triadic, or analogous to get hue-rotated swatches from the same base.

  4. Copy the CSS

    Use each stop's css field (formatOklchCss) for oklch() declarations or the hex field for sRGB-safe fallbacks.

Use cases

Designing band-free gradients

Interpolate in OKLCH instead of sRGB so mid-tones stay perceptually even without gray dead zones.

Taming wide-gamut brand colors

Reduce chroma deterministically for sRGB delivery while keeping the intended lightness and hue.

Generating palette harmonies

Derive complementary, triadic, or analogous ramps from one brand hex for UI themes.

Common mistakes

Mistake:Expecting hexToOklch to clamp out-of-gamut chroma.

Fix:Conversion preserves the raw value — call mapToSrgbGamut (or oklchToHex, which maps internally) before displaying.

Mistake:Interpolating hue the long way around the wheel.

Fix:interpolateOklch already takes the shortest delta, so 350° to 10° passes through 0° rather than sweeping 340°.

Mistake:Comparing gradient hex case-sensitively.

Fix:oklchToHex emits uppercase #RRGGBB — normalize expected values with .toUpperCase().

Frequently asked questions

What does this tool do?

It builds OKLCH gradients with generateOklchGradient, plus harmonies with generateHarmony and gamut mapping with mapToSrgbGamut — every stop returns oklch, hex, and css fields.

How do I map a wide-gamut color into sRGB?

Call mapToSrgbGamut({ l: 0.7, c: 0.4, h: 30 }) — chroma shrinks until the color fits while l and h stay fixed, and oklchToHex gives the fallback hex.

Is my palette uploaded or stored?

No. Hex parsing, interpolation, and gamut math run entirely in your browser.

Why is my gradient endpoint different?

Endpoints are included verbatim (#FF0000 stays #FF0000) — check that steps is at least 2 and compare uppercase hex, since oklchToHex emits uppercase.

References & standards