CSS Colors Cheat Sheet: hex, rgb, hsl, oklch, color-mix() and Relative Colors
Checked against CSS CSS Color 4 (W3C CR Draft, 23 Nov 2026), MDN Nov 2026; conversions run with culori 4.0.2 on 28 November 2026. Each section links to the official docs it was checked against.
This sheet covers every way to write a colour in modern CSS, for developers moving a design system off hex codes. It follows the CSS Color 4 draft dated 23 Nov 2026 and MDN's colour pages. Every converted value below was computed with the culori 4.0.2 library in Node, not copied from a chart.
When to use what
Hex is fine for one-off values copied from a design tool, and the 8-digit form carries alpha. For anything you plan to tint, shade or theme, write oklch(). Its L channel is perceived lightness, so two colours with the same L look equally bright, which hsl() can't promise: hsl(60 100% 50%) yellow and hsl(240 100% 50%) blue share an L but look nothing alike.
Use color-mix() when you need a blend of two known colours, like a hover state 10% darker than the brand colour. Use relative colour syntax (oklch(from var(--brand) ...)) when you want to change one channel of a colour you don't know in advance, such as a token. Both let you keep one source colour per theme and derive the rest.
currentColor is the quiet workhorse: icons and borders that use it follow the text colour automatically, so a link's SVG arrow turns red on hover with no extra rule.
The OKLCH colour picker shows when a value falls outside sRGB, the colour converter moves between notations, and the shade generator builds a 50 to 950 scale. Check contrast before you ship; the WCAG contrast post explains the ratios.
#f09Three-digit hex; each digit doubles, so it equals #ff0099
#f098Four-digit hex where the last digit is alpha (8 means 0x88, about 53%)
#ff009980Eight-digit hex; 80 is alpha, which culori reads as rgba(255, 0, 153, 0.5)
transparentFully transparent black, the same as rgb(0 0 0 / 0%)
currentColorThe element's color value; on color itself it takes the inherited colour
light-dark(white, black)Picks the first colour in a light scheme and the second in a dark one
rgba() and hsla() are aliases of rgb() and hsl() per CSS Color 4. Only the space-separated form accepts none.
rgb(255 0 153 / 80%)Modern space-separated RGB with alpha after a slash
rgb(255, 0, 153)Legacy comma syntax; still valid but can't take none
hsl(324 100% 50%)Hue, saturation, lightness; culori converts #ff0099 to exactly this
hwb(194 0% 0% / 0.5)Hue plus how much white and black to mix in, often easier to reason about than HSL
oklch L runs 0 to 1 (or 0% to 100%), C from 0 with 100% meaning 0.4, and H is an angle. Hue angles differ between hsl, lch and oklch, so don't copy a hue across.
oklch(0.623 0.188 259.8)#3b82f6 converted with culori; nudge only L to make lighter or darker steps
oklch(60% 0.15 50 / 0.5)OKLCH with a percentage lightness and half alpha
oklab(59% 0.1 0.1)Oklab with a and b axes instead of chroma and hue; the default space for color-mix()
lch(52.2% 72.2 50)CIE LCH with lightness, chroma and hue; its hue angles differ from oklch
lab(50% 40 59.5)CIE Lab with lightness and two opponent axes
color(display-p3 1 0.5 0.5)A colour in a named space such as display-p3; can exceed sRGB
color-mix(in oklab, #3b82f6, white)50/50 blend; culori gives #9ec3ff in oklab versus #9dc1fb in sRGB
color-mix(red, blue)No space given, so it mixes in oklab
color-mix(in oklab, #a71e14 25%, white)One percentage given, so white gets the remaining 75%
color-mix(in srgb, red 30%, blue 30%)Percentages under 100% are normalised to 50/50 and the result gets 60% alpha
color-mix(in lch longer hue, a, b)Polar spaces take a hue method: shorter (default), longer, increasing or decreasing
color-mix(in oklab, teal 20%, olive 30%, blue 50%)Mixes three or more colours in one call
oklch(from var(--brand) calc(l + 0.1) c h)Lighter step of a token; for #3b82f6 culori gives #5aa2ff
oklch(from var(--brand) calc(l - 0.1) c h)Darker step; for #3b82f6 culori gives #1a62d3
rgb(from teal r g b / 50%)Same colour at half opacity, without knowing its channels
hsl(from red 240deg s l)Keeps saturation and lightness but swaps the hue
rgb(from rgb(200 170 0) b g r)Channels can be reordered; this yields rgb(0 170 200)
@supports (color: hsl(from white h s l))Feature test; use a literal colour because tests with var() always pass
Worked example: Turning one brand colour into hover, pressed and muted states
Start from a single token and derive the rest, so a theme only overrides one variable.
:root { --brand: #3b82f6; }
.btn { background: var(--brand); color: white; }
.btn:hover { background: oklch(from var(--brand) calc(l - 0.1) c h); }
.btn:active { background: color-mix(in oklab, var(--brand), black 20%); }
.btn-ghost { background: oklch(from var(--brand) l c h / 0.12); color: var(--brand); }
I ran the first conversion with culori 4.0.2:
#3b82f6 -> oklch(0.6230830326348528 0.18801473450792208 259.81452852548136)
l - 0.1 -> #1a62d3
l + 0.1 -> #5aa2ff
The blue keeps its hue and chroma, and only perceived lightness drops by 0.1, which is why the hover shade looks like the same blue rather than a muddier one. The pressed state uses color-mix() because the mixing partner is fixed. The ghost style keeps the brand hue at 12% alpha so it works on any background. If you push chroma too high in a derived step, the colour can leave sRGB: culori reported that oklch(0.7 0.3 150) is not displayable and its gamut-clamped version is oklch(0.7 0.193 150), #00be58.
Common mistakes
Building tints by changing HSL lightness
HSL lightness isn't perceptual, so yellows wash out and blues stay dark. Step the L channel of
oklch()instead.Copying a hue number from hsl() into oklch()
The hue angles belong to different colour spaces. Convert the whole colour with a tool rather than reusing the angle.
Writing
noneinside legacy comma syntax likergb(255, none, 0)noneonly works in the space-separated form, so writergb(255 none 0).Testing relative colour support with
@supports (color: rgb(from var(--x) r g b))Tests containing
var()always pass. Use a literal colour such aswhitein the condition.Expecting an out-of-gamut oklch value to show exactly as written
The browser gamut-maps it, lowering chroma on sRGB screens. Keep chroma within sRGB if colours must match across displays.
Related cheat sheets
Sources
- https://developer.mozilla.org/en-US/docs/Web/CSS/color_value
- https://www.w3.org/TR/css-color-4/
- https://developer.mozilla.org/en-US/docs/Web/CSS/color_value/color-mix
- https://developer.mozilla.org/en-US/docs/Web/CSS/CSS_colors/Relative_colors
- https://developer.mozilla.org/en-US/docs/Web/CSS/color_value/oklch
- https://github.com/Evercoder/culori
How we research: where our facts come from, how often we re-check them, and why no one can pay for a review or a verdict.