Color
Functions that produce a <color>, from the long-standing rgb() and hsl() to the perceptual Lab and OKLCH spaces, plus functions that mix, adjust or choose colours. They work anywhere a colour is accepted, including inside gradients. The properties that take colours are under Color & backgrounds; the <color> type itself is under Types.
sRGB colours
rgb()
A colour from red, green and blue channels, each a number from 0 to 255 or a percentage, with an optional alpha after a slash. This is the same sRGB space that hex colours use.
| Syntax | [ <legacy-rgb-syntax> | <modern-rgb-syntax> ] |
|---|---|
| Returns | <color> |
| Support | rgb(): Chrome 1 · Firefox 1 · Safari 1Space-separated channels and alpha: Chrome 65 · Firefox 52 · Safari 12.1 Relative syntax ( from): Chrome 122 · Firefox 128 · Safari 18 |
| Spec | css-color-4 |
The modern syntax is rgb( [ from <color> ]? [ <number> | <percentage> | none ]{3} [ / [ <alpha-value> | none ] ]? ), with spaces between channels. The legacy syntax separates the channels with commas, takes an optional fourth alpha argument, and does not allow mixing numbers and percentages or none.
Relative colour syntax. Start the arguments with from and a colour, and that origin colour is converted to the function's space. Inside the function, the channel keywords (r, g, b and alpha here) stand for the origin's channel values, so you can keep them, replace them or change them with calc(). Every colour function on this page except light-dark(), contrast-color() and the three mix functions accepts the same from form with its own channel keywords.
color: rgb(30 144 255);
background: rgb(30 144 255 / 0.2);
border-color: rgb(from var(--brand) r g b / 50%);
rgba()
A legacy alias of rgb(). It accepts exactly the same arguments and gives the same result; it dates from when rgb() did not take an alpha value. New code can use rgb() throughout.
| Syntax | [ <legacy-rgba-syntax> | <modern-rgba-syntax> ] |
|---|---|
| Returns | <color> |
| Support | Chrome 1 · Firefox 1 · Safari 1 |
| Spec | css-color-4 |
hsl()
An sRGB colour given as hue, saturation and lightness. The hue is an angle around the colour wheel (a plain number means degrees: 0 red, 120 green, 240 blue); saturation and lightness are percentages.
| Syntax | [ <legacy-hsl-syntax> | <modern-hsl-syntax> ] |
|---|---|
| Returns | <color> |
| Support | hsl(): Chrome 1 · Firefox 1 · Safari 3.1Relative syntax ( from): Chrome 125 · Firefox 128 · Safari 18 |
| Spec | css-color-4 |
As with rgb(), the modern syntax separates the values with spaces and puts alpha after a slash; the legacy syntax uses commas. HSL lightness is not perceptual: a yellow and a blue with the same lightness look very different in brightness. Use oklch() when that matters.
hsla()
A legacy alias of hsl() with the same arguments and result.
| Syntax | [ <legacy-hsla-syntax> | <modern-hsla-syntax> ] |
|---|---|
| Returns | <color> |
| Support | Chrome 1 · Firefox 1 · Safari 3.1 |
| Spec | css-color-4 |
hwb()
An sRGB colour given as a hue plus how much white and how much black to mix into it, which is close to how people pick colours from a palette.
| Syntax | hwb([from <color>]? [<hue> | none] [<percentage> | <number> | none] [<percentage> | <number> | none] [ / [<alpha-value> | none] ]? ) |
|---|---|
| Returns | <color> |
| Support | Chrome 101 · Firefox 96 · Safari 15 |
| Spec | css-color-5 |
Lab & LCH colours
lab()
A colour in the CIE Lab space: lightness from 0 to 100, then two axes, a (green to red) and b (blue to yellow). Lab can describe every visible colour, not just those inside sRGB.
| Syntax | lab([from <color>]? [<percentage> | <number> | none] [<percentage> | <number> | none] [<percentage> | <number> | none] [ / [<alpha-value> | none] ]? ) |
|---|---|
| Returns | <color> |
| Support | Chrome 111 · Firefox 113 · Safari 15 |
| Spec | css-color-5 |
lch()
The polar form of Lab: lightness, chroma (how colourful) and hue angle. Changing the hue keeps the lightness the same, which HSL does not.
| Syntax | lch([from <color>]? [<percentage> | <number> | none] [<percentage> | <number> | none] [<hue> | none] [ / [<alpha-value> | none] ]? ) |
|---|---|
| Returns | <color> |
| Support | Chrome 111 · Firefox 113 · Safari 15 |
| Spec | css-color-5 |
oklab()
A colour in the OKLab space, a refinement of Lab whose lightness and hue stay more even across the whole range. Lightness runs from 0 to 1 (or 0% to 100%); a and b are roughly between -0.4 and 0.4.
| Syntax | oklab([from <color>]? [<percentage> | <number> | none] [<percentage> | <number> | none] [<percentage> | <number> | none] [ / [<alpha-value> | none] ]? ) |
|---|---|
| Returns | <color> |
| Support | Chrome 111 · Firefox 113 · Safari 15.4 |
| Spec | css-color-5 |
oklch()
The polar form of OKLab: lightness from 0 to 1, chroma from 0 to about 0.4, and a hue angle. It is the most practical space for building palettes, because equal steps in lightness look like equal steps, whatever the hue.
| Syntax | oklch([from <color>]? [<percentage> | <number> | none] [<percentage> | <number> | none] [<hue> | none] [ / [<alpha-value> | none] ]? ) |
|---|---|
| Returns | <color> |
| Support | oklch(): Chrome 111 · Firefox 113 · Safari 15.4Relative syntax ( from): Chrome 122 · Firefox 128 · Safari 18Relative syntax from currentcolor: Chrome 131 · Firefox 133 · Safari 18 |
| Spec | css-color-5 |
In relative syntax the channel keywords are l, c, h and alpha. Adjusting l darkens or lightens a colour without shifting its hue, and rotating h gives harmonious companions.
--brand: oklch(62% 0.19 255);
--brand-dark: oklch(from var(--brand) calc(l - 0.15) c h);
--brand-muted: oklch(from var(--brand) l calc(c / 2) h);
--accent: oklch(from var(--brand) l c calc(h + 180));
Other colour spaces
color()
A colour in a named colour space: srgb, srgb-linear, display-p3, a98-rgb, prophoto-rgb, rec2020, or the XYZ spaces xyz, xyz-d50 and xyz-d65. Use it to reach the wider gamuts of modern displays.
| Syntax | color( [from <color>]? <colorspace-params> [ / [ <alpha-value> | none ] ]? ) |
|---|---|
| Returns | <color> |
| Support | Chrome 111 · Firefox 113 · Safari 15 |
| Spec | css-color-5 |
<colorspace-params> is the colour-space name followed by its three channel values, usually numbers from 0 to 1.
color: color(display-p3 1 0.2 0.1);
Mixing, choosing & adjusting
color-mix()
Mixes colours in a chosen colour space, with optional percentages for how much of each to use. The colour space after in changes the result: oklab and oklch usually give the most even blends.
| Syntax | color-mix( <color-interpolation-method>? , [ <color> && <percentage [0,100]>? ]#) |
|---|---|
| Returns | <color> |
| Support | color-mix(): Chrome 111 · Firefox 113 · Safari 16.2More than two colours: Chrome no · Firefox 150 · Safari 27 |
| Spec | css-color-5 |
<color-interpolation-method> is in followed by a colour space, and for polar spaces (hsl, hwb, lch, oklch) an optional shorter, longer, increasing or decreasing hue. Leaving out a percentage splits the remainder evenly.
background: color-mix(in oklch, var(--brand) 20%, white);
border-color: color-mix(in srgb, currentcolor 30%, transparent);
light-dark()
Picks the first value when the element's used colour scheme is light and the second when it is dark. It only switches when color-scheme allows both, for example color-scheme: light dark on the root.
| Syntax | <light-dark-color> | <light-dark-image> |
|---|---|
| Returns | <color>, or <image> for the image form |
| Support | Colours: Chrome 123 · Firefox 120 · Safari 17.5 Images: Chrome 150 · Firefox 150 · Safari 27 |
| Spec | css-color-5 |
The colour form is light-dark(<color>, <color>); the image form takes two images, either of which may be none.
:root { color-scheme: light dark; }
body { background: light-dark(#fff, #111); color: light-dark(#111, #eee); }
contrast-color()
Returns white or black, whichever contrasts more with the given colour. Use it for text on a background colour you do not control, such as a user-chosen tag colour.
| Syntax | contrast-color( <color> ) |
|---|---|
| Returns | <color> |
| Support | Chrome 147 · Firefox 146 · Safari 26 |
| Spec | css-color-5 |
Picking the higher-contrast of black and white does not guarantee the result meets accessibility contrast guidelines for every mid-tone background.
.tag { background: var(--tag); color: contrast-color(var(--tag)); }
alpha()
Takes a colour and changes only its alpha, keeping the colour in whatever space it was given. It is a short form of the relative colour syntax for the common case of making a colour more or less transparent.
| Syntax | alpha(from <color> / [<alpha-value> | none]) |
|---|---|
| Returns | <color> |
| Support | Chrome 152 · Firefox 155 · Safari 27 |
| Spec | css-color-5 |
box-shadow: 0 4px 12px alpha(from var(--brand) / 25%);
palette-mix()
Mixes two font palettes for colour fonts, for use in font-palette. It works like color-mix(), blending each pair of matching palette entries, and lets a transition move smoothly from one palette to another.
| Syntax | palette-mix( <color-interpolation-method>? , [ <'font-palette'> && <percentage [0,100]>? ]# ) |
|---|---|
| Returns | A font palette, as a value of font-palette |
| Support | Chrome 121 · Firefox no · Safari no |
| Spec | css-fonts-4 |
dynamic-range-limit-mix()
Mixes values of dynamic-range-limit by percentage, giving a limit on HDR brightness between those keywords. It also lets that limit be transitioned.
| Syntax | dynamic-range-limit-mix( [ <'dynamic-range-limit'> && <percentage [0,100]> ]# ) |
|---|---|
| Returns | A value of dynamic-range-limit |
| Support | Chrome 136 · Firefox no · Safari no |
| Spec | css-color-hdr-1 |