Color Gradients and Interpolation

A gradient looks simple: draw a line between two colors and fill the gap. But the gap has no single answer. The color space, transfer function, hue path, stop placement, bit depth, and dither strategy all decide what appears between the endpoints.

Digital 27 5 Live Demos Advanced Interpolation
6
Spaces compared
2.4
sRGB transfer exponent
4
Hue routes
OKLCH
Best UI default
01

What a gradient really is

A gradient is a function of position that returns a color. Give it a fraction t from 0 to 1 and it answers: what color lives here? The obvious formula is a linear interpolation, but that formula only has meaning inside a specific coordinate system. Change the space and the midpoint changes.

color(t) = A * (1 - t) + B * t The equation is simple. The hard part is deciding what A and B mean: gamma sRGB, linear light, HSL, Lab, OKLab, OKLCH, or another space.
02

The space decides everything

Pick two endpoint colors and watch the same blend computed six ways. Opposite saturated hues show the problem clearly: gamma sRGB cuts through dull low-chroma territory, while perceptual spaces preserve a more intentional path.

Interactive 01 - Six spaces, one blend

The same two colors, interpolated six ways

Try blue to yellow, red to green, and magenta to cyan. The midpoint is the diagnostic: dull, too dark, uneven, clipped, or perceptually steady.

03

Gamma vs linear blending

sRGB numbers are gamma encoded for storage and display. They are not proportional to physical light. If you average encoded numbers directly, bright mixtures come out too dark. The physical recipe is: decode to linear light, blend, encode back to sRGB.

Interactive 02 - The dark-middle bug

Blend bright complements in gamma sRGB vs linear light

The top bar averages encoded sRGB values. The bottom bar averages linear-light values. Glows, compositing, blurs, and physically plausible lighting need the bottom behavior.

Gamma sRGB blendencoded math
Linear-light blendphysical math
04

Hue paths in cylindrical spaces

HSL and OKLCH express hue as an angle. Angles wrap. From 20 degrees to 300 degrees you can go the short way backward or the long way forward. CSS now exposes this choice with shorter, longer, increasing, and decreasing hue interpolation.

Interactive 03 - Hue route control

Same endpoints, different journey through hue

Drag the endpoints and quantize the steps. The short route keeps a gradient restrained; the long route can deliberately create a broad spectrum sweep.

OKLCH - shorter hue arcDelta 120 deg
OKLCH - longer hue arcDelta 240 deg
05

Easing, stops, and position

Linear interpolation moves t at a constant rate. Real gradients often need the transition to happen sooner, later, or through a deliberate intermediate stop. Easing changes where the blend accelerates. A stop changes what the gradient passes through. A color hint moves the midpoint without adding a new color.

Linear position
Color changes evenly across distance. It is predictable and easy to compare.
Eased position
An ease-in or ease-out curve concentrates change near one side of the ramp.
Multi-stop
Several two-color gradients joined together. Each segment still has an interpolation space.
Color hint
A bare percentage between two stops that shifts the visual midpoint without adding a new color.
06

Banding and dithering

A mathematically smooth ramp can still look striped. Long subtle gradients may need more distinct levels than an 8-bit target can store. Dithering adds tiny structured variation so the eye averages adjacent levels back into a smooth transition.

Interactive 04 - Banding and dithering

Crush the bit depth, then dither it away

Lower the bit depth to force visible steps. Turn dithering on to scatter the thresholds and reduce visible stripes at normal viewing distance.

07

Advanced interpolation workbench

Real production gradients combine every issue at once: space, hue route, stop model, quantization, dithering, alpha over a surface, and export syntax. This lab lets you tune those variables together and inspect the result.

Interactive 05 - Advanced interpolation workbench

Build, audit, quantize, and export a production gradient

The main canvas shows your selected interpolation, a gamma-sRGB reference, a quantized output row, sample markers, and stop positions. The meters flag muddy midpoint risk, banding pressure, gamut pressure, contrast loss, and perceptual smoothness.

Sample

Waiting for sample...

Audit

Waiting for audit...

Muddy mid
0%
Banding
0%
Gamut
0%
Contrast
0%
Smoothness
0%

CSS output

linear-gradient(...)
08

Choosing a space

Space Strength Weakness Use for
Gamma sRGBFast, legacy defaultGray and dark middlesShort blends between similar colors
Linear sRGBPhysical light mixingStill desaturates across hueCompositing, blur, glow, lighting
HSLIntuitive hue sweepsUneven lightnessQuick hue ramps and decorative rainbows
CIELABPerceptual distanceCan leave display gamutScientific ramps and analysis
OKLabModern perceptual cartesian blendNo direct hue-route knobSmooth UI and generative palettes
OKLCHEven lightness, stable chroma, hue controlNeeds fallback for older stacksBest default for interface gradients
There is no neutral way to go from one color to another. Every gradient is an opinion about what should happen in the middle. Editorial summary - interpolating color
09

From theory to code

Modern CSS can name the interpolation space and hue route directly. Canvas and WebGL require you to do the same conversion manually: decode, convert, interpolate, gamut-map, quantize, and write pixels.

background: linear-gradient(90deg in oklch shorter hue, #2457ff, #ff4fd8 50%, #ffe15a); Without an "in <space>" hint, CSS gradients still default to sRGB interpolation.
10

Pitfalls and gotchas

Gray dead zone
Opposite saturated hues in gamma sRGB can pass through low chroma.
Dark mud
Averaging gamma-encoded values makes bright blends too dark.
Accidental rainbow
A cylindrical blend can take the long hue route unless you choose the route explicitly.
Out-of-gamut bends
Lab and OKLCH paths can leave sRGB, then flatten after clipping.
Banding
Long subtle ramps can exceed available bit depth. Dither or use higher precision.
Stop creases
Segments meeting with mismatched slopes show a visible join.
11

Test your understanding

Six questions on interpolation spaces, linear light, hue routes, and banding.

Quick check

Loading...
 
Question 1 of 6
12

Continue your journey

Gradients connect perceptual spaces, gamma, bit depth, and design systems. These articles go deeper into each piece.