CSS offers more than one way to describe color: from the most basic hexadecimal values, to HSL which matches how designers mix colors, to OKLCH — a perceptually uniform color space that browsers only widely supported in recent years. Choosing the right notation makes maintaining and adjusting colors much easier.
Traditional Notations
Notation
Example
Description
Keyword
rebeccapurple
148 predefined color names; readable but limited precision
Hexadecimal
#8a5a2e
The most common; the 4/8-digit forms also include alpha
rgb()
rgb(138 90 46)
Red, green, blue channels; 0–255 or percentages
.accent {
color: #8a5a2e;
color: rgb(138 90 46); /* equivalent syntax; space-separated is the modern form */
}
hsl: An Intuitive Way to Mix Colors
hsl(hue saturation lightness) describes color with three dimensions closer to human intuition. When you want something "a bit darker" or "more vivid", you do not need to mentally recompute all three RGB channels at once.
:root {
--accent: hsl(30 47% 36%);
--accent-light: hsl(30 47% 56%); /* only lightness changes; the color relationship stays consistent */
}
Same hue, different lightness
30%
45%
60%
75%
Two Ways to Write Transparency
Modern syntax lets you append alpha with a slash inside the color function, so you no longer need to memorize "a-suffix" functions like rgba() / hsla() (they still work, but are now legacy):
Easy to confuseopacity affects the entire element (including its content and children), so text fades along with it; the alpha channel in a color value affects only that one color. They serve different purposes, so do not mix them up.
oklch: A Perceptually Uniform Modern Color Space
HSL has a hidden problem: the same lightness value is not perceived as equally bright across different hues (for example, a yellow at the same lightness looks much brighter than a blue). OKLCH defines colors in a perceptually uniform way — the same lightness difference looks consistent under any hue, which makes it ideal for generating color scales.
Mainstream modern browsers already support oklch; prefer it when generating design-system color scales. For projects that still need to support older browsers, keep hsl as a fallback — CSS automatically ignores property values it cannot parse and keeps the last valid declaration.
currentColor and transparent
currentColor is a special keyword representing the element's currently effective color value, letting properties like border and shadow "inherit" the text color and reducing repeated declarations:
.icon-btn {
color: #3f5d54;
border: 1px solid currentColor; /* the border automatically follows the text color */
}
color-mix()
No manual calculation needed — mix two colors proportionally right in CSS. Very useful for generating derived colors like hover and disabled states: