Colour Picker & Converter · Tutorial
How to use OKLCH colours in your CSS
7 min readintermediateUpdated
Your stylesheet uses HEX colours, and making hover, pressed and disabled variants means guessing new codes. This tutorial converts a brand colour to OKLCH, explains its lightness, chroma and hue, and shows how to make reliable variants by changing one number.
What you need
- The Colour Picker & Converter
- Your brand colour, or the sample from the Try it button
Steps
Enter the colour
Type your colour in any format. The sample is
oklch(62% 0.19 255), a strong blue. The tool shows it as HEX, RGB, HSL and the other formats, so you can see it matches the colour in your design files.Read the three OKLCH numbers
The first number is lightness, from 0% (black) to 100% (white). The second is chroma, how colourful it is; around 0.1 to 0.2 is a strong colour and 0 is grey. The third is the hue angle, from 0 to 360 degrees. Blue sits around 250.
Make a hover and a pressed state
To make a darker version, lower only the lightness. Paste the new value into the tool to check it. Because OKLCH is perceptual, the hue looks the same, unlike darkening in HSL, which can drift toward purple or grey.
--brand: oklch(62% 0.19 255); --brand-hover: oklch(55% 0.19 255); --brand-pressed: oklch(48% 0.19 255);Make a soft background tint
For a light background in the same family, raise the lightness and lower the chroma, for example
oklch(95% 0.03 255). Check the contrast numbers: dark text on this tint stays easy to read.Add a fallback for old browsers
Browsers from before 2023 don’t understand OKLCH. Copy the HEX value from the tool and put it first, followed by the OKLCH line. Newer browsers use the second one.
background: #2f6fd8; background: oklch(62% 0.19 255);
Try it yourself
Opens the Colour Picker & Converter with this tutorial's sample loaded.
Common mistakes
- Chroma too high for the screen
- Very high chroma values can’t be shown on normal sRGB screens. The tool maps them to the nearest colour that can, so check the HEX result.
- Writing lightness without a percent sign
oklch(62 0.19 255)means 6200% lightness. Write62%or0.62.- Changing hue to darken
- Keep the hue fixed when making variants. Changing it gives a different colour, not a darker one.
Next steps
Go back to the Colour Picker & Converter, or keep going with one of these:
FAQ
Do all browsers support OKLCH?
Chrome, Edge, Firefox and Safari have supported it since 2023. Use a HEX fallback if you need to support older versions.
Can I generate a whole scale automatically?
Yes. The Colour Palette Generator makes an 11-step scale in OKLCH from one colour.