Sub topic 9
Hue interpolation: shorter, longer, increasing, decreasing
This chapter assumes you can write oklch() colors, use color-mix() with an interpolation color space, and know that hue in OKLCH is an angle from 0 to 360 degrees. It covers what happens to hue when a mix or gradient runs between two colors, and how to choose the path.
Why hue needs its own rule
Lightness and chroma are ordinary numbers. Going from 40% to 80% lightness, the midpoint is 60%, and there is only one way to get there.
Hue is an angle, so it sits on a circle. To get from 20° to 300°, you can go up through 160° or go down through 340°. Both paths are valid, and they pass through different colors. CSS needs a rule to pick one, and it lets you override that rule.
The rule applies only in polar color spaces, which store hue as an angle: hsl, hwb, lch and oklch. Rectangular spaces such as srgb and oklab have no hue channel. A hue method on them is a syntax error and invalidates the whole value.
The syntax
You write the hue method after the color space and before the word hue:
.swatch-a {
background: color-mix(in oklch, red, blue);
}
.swatch-b {
background: color-mix(in oklch longer hue, red, blue);
}The first mix takes the default method, shorter. The second takes the long way around the circle. The four keywords are:
| Keyword | Meaning |
|---|---|
| `shorter hue` | Take the shorter arc between the two hues. This is the default. |
| `longer hue` | Take the longer arc. |
| `increasing hue` | Always move upward in angle, wrapping past 360° if needed. |
| `decreasing hue` | Always move downward in angle, wrapping past 0° if needed. |
shorter and longer depend on the distance between the hues. increasing and decreasing depend on direction, whatever the distance.
Worked example: red to blue
In OKLCH, red has a hue of about 29° and blue about 264°. The gap is about 235° going up and about 125° going down.
shortertakes the 125° arc. It moves downward from 29°, wraps below 0° (so 330° and so on) and ends at 264°. The path crosses magenta and purple. The midpoint hue is about 327°, a purple.longertakes the 235° arc. It moves upward through orange, yellow, green and cyan to blue. The midpoint hue is about 147°, a green.
The default red-to-blue mix looks like a purple, which is usually what people expect. The longer version looks like a rainbow detour and gives a green midpoint, which surprises many people.
You can check the paths on your own screen:
.bar {
height: 2rem;
margin-block: 0.5rem;
}
.bar-shorter {
background: linear-gradient(in oklch shorter hue, red, blue);
}
.bar-longer {
background: linear-gradient(in oklch longer hue, red, blue);
}
.bar-increasing {
background: linear-gradient(in oklch increasing hue, red, blue);
}
.bar-decreasing {
background: linear-gradient(in oklch decreasing hue, red, blue);
}Gradients accept the same in <space> <method> hue form as color-mix(). They are the easiest way to see a hue path, because you see every step and not only the midpoint. In this example increasing matches longer and decreasing matches shorter.
How the browser does it
The browser first normalizes both hues into the range 0 to 360. It then adjusts one hue by 360° so that a plain linear interpolation takes the path you asked for. Call the start hue h1 and the end hue h2. The rules from the CSS Color specification are:
shorter: ifh2 - h1 > 180, add 360 toh1. Ifh2 - h1 < -180, add 360 toh2.longer: if0 < h2 - h1 < 180, add 360 toh1. If-180 < h2 - h1 <= 0, add 360 toh2.increasing: ifh2 < h1, add 360 toh2.decreasing: ifh1 < h2, add 360 toh1.
After the adjustment, the result is h1 + (h2 - h1) * t, wrapped back into 0 to 360. Here t is the mix fraction, from 0 to 1. This script applies the rules. You can run it with Node.js:
function wrap(h) {
return ((h % 360) + 360) % 360;
}
function mixHue(a, b, t, method) {
let h1 = wrap(a);
let h2 = wrap(b);
const d = h2 - h1;
if (method === "shorter") {
if (d > 180) h1 += 360;
else if (d < -180) h2 += 360;
} else if (method === "longer") {
if (d > 0 && d < 180) h1 += 360;
else if (d > -180 && d <= 0) h2 += 360;
} else if (method === "increasing") {
if (h2 < h1) h2 += 360;
} else if (method === "decreasing") {
if (h1 < h2) h1 += 360;
}
return wrap(h1 + (h2 - h1) * t);
}
const pairs = [
[29, 264],
[350, 20],
];
const methods = ["shorter", "longer", "increasing", "decreasing"];
for (const [a, b] of pairs) {
for (const method of methods) {
console.log(`${a} -> ${b} ${method}: ${mixHue(a, b, 0.5, method).toFixed(1)}`);
}
}The midpoints it prints are:
| Start hue | End hue | shorter | longer | increasing | decreasing |
|---|---|---|---|---|---|
| 29 | 264 | 326.5 | 146.5 | 146.5 | 326.5 |
| 350 | 20 | 5.0 | 185.0 | 5.0 | 185.0 |
The second row crosses the 0°/360° seam. Here shorter and increasing agree, because the short path goes up through 0°. longer and decreasing agree, because the long path goes down through 180°.
The diagram shows how to choose a method.
Choosing a method
shorter: the default
Use it when the two colors are related and you want a transition that stays between them. A mix of a brand blue and a teal should not detour through red.
longer: rainbow effects
Use it deliberately for rainbow-like gradients, spectrum swatches, or data visualization ramps that need many distinguishable hues. For ordinary UI states it nearly always looks wrong, because the middle of the mix is a color unrelated to either end.
increasing and decreasing: stable direction
These two are useful when the hues come from variables, or when you animate or step through values. With shorter, changing a hue by a small amount can flip the path when the distance crosses 180°. This makes the midpoint jump to the opposite side of the wheel. A fixed direction stays predictable as inputs change.
This matters for theming. If users or a script can change a base hue, increasing or decreasing keeps the transition on the same side. The behavior is easier to reason about.
:root {
--from-hue: 250;
--to-hue: 20;
}
.banner {
background: linear-gradient(
in oklch increasing hue,
oklch(65% 0.18 var(--from-hue)),
oklch(65% 0.18 var(--to-hue))
);
}With these values, increasing goes from 250° up through 360° to 20°. This is 130° and happens to match shorter. If you changed --to-hue to 100, shorter would flip to go downward through blue-green, while increasing would still go up through 360°, 0° and into 100° the long way. The direction is the same, but the distance changes. Pick the method whose behavior you can describe in one sentence.
Powerless hue: mixing with white, black or gray
An OKLCH color with zero or near-zero chroma has no visible hue. CSS treats such a hue as missing (written none in the specification) and does not use it. During interpolation, a missing hue takes the hue of the other color. That is why this tint from the palette chapter works:
.card {
background: color-mix(in oklch, var(--brand) 15%, white);
}white has a missing hue in OKLCH. The mix therefore keeps the hue of --brand and never swings toward some arbitrary angle. A hue method is irrelevant here, because only one color has a hue.
Compare a mix of two chromatic colors, such as color-mix(in oklch, var(--brand), orange). Both have hue, so the method matters.
You can write a missing channel yourself:
.example {
background: color-mix(in oklch, oklch(60% 0.15 none), oklch(60% 0.15 120));
}The first color has no hue, so the mix uses 120° from the second color.
Mixing with black and white in other polar spaces
In hsl, black, white and gray also have no meaningful hue when saturation is zero. Mixing in HSL with such a color behaves the same way. This is one reason color-mix with white or black is stable in polar spaces, as long as the other color is chromatic.
Common mistakes
- Using a hue method in
oklaborsrgb.color-mix(in oklab longer hue, red, blue)is invalid. Use a polar space, or drop the method. - Putting the method in the wrong place. The order is
in <space> <method> hue. Writingin longer hue oklchfails. - Leaving out the word
hue.longeralone is invalid. The keyword always ends withhue. - Assuming
shorteralways means "natural". Two hues exactly 180° apart have no shorter path. The result follows the specification's tie rule, and the midpoint is an unrelated color. Avoid mixing near-complementary hues without checking the result by eye. - Expecting the hue method to change lightness or chroma. It affects the hue channel only. Lightness and chroma still interpolate linearly, so a
longersweep through green can ask for chroma that the display cannot show. The browser then maps the result into gamut, which can make the middle of a gradient look duller than the ends.
Hue methods and contrast
A hue path can pass through colors of very different perceived brightness, even when OKLCH lightness stays constant, because gamut limits and chroma changes still affect appearance. If text sits on a gradient made with longer hue, check contrast at several points, not only at the ends. The later contrast chapter returns to this.
Summary
- Hue is an angle, so interpolation needs a path rule. The rule applies in polar spaces only:
hsl,hwb,lch,oklch. - The syntax is
in oklch <method> hue, with the method one ofshorter,longer,increasing,decreasing. shorteris the default and stays between the colors.longersweeps the other way.increasinganddecreasingfix the direction.- A color with no chroma has a missing hue, and the other color's hue is used.
- Check gradients visually, and check contrast along the path, not just at the endpoints.
Exercise
A gradient needs to go from oklch(70% 0.15 350) to oklch(70% 0.15 20). Which hue method makes the gradient travel through hues such as 180° (cyan-green)? Which one keeps the hues in the red to pink range?
Show answer
longer hue (or decreasing hue) travels down from 350° through 180° to 20°, so it passes through cyan-green. shorter hue (the default, or increasing hue) goes up from 350° through 360° to 20°, which stays in the pink to red range.
Exercise
Why does color-mix(in oklab longer hue, red, blue) not work, and how would you fix it?
Show answer
oklab is a rectangular color space with no hue channel, so a hue interpolation method is invalid there. Change the space to a polar one, for example color-mix(in oklch longer hue, red, blue), or remove longer hue if you want to stay in oklab.
Exercise
You mix color-mix(in oklch, var(--brand) 20%, white). Does the hue method matter for the result, and why?
Show answer
No. white has zero chroma, so its hue is missing and the mix uses the hue of --brand. Only one color provides a hue, so there is no path to choose between.