Color formats
| Format | Example | Used for |
|---|---|---|
| HEX | #4F46E5 | CSS and design tools. 8-digit HEX adds transparency. |
| RGB | rgb(79, 70, 229) | Screens: red, green and blue light from 0 to 255. |
| HSL | hsl(243, 75%, 59%) | Adjusting colors by hand: hue, saturation, lightness. |
| HSV / HSB | hsv(243, 69%, 90%) | Color pickers in Photoshop and Figma. |
| OKLCH | oklch(51.06% 0.2301 276.97) | Modern CSS and Tailwind CSS v4: lightness, chroma and hue in a perceptually even space. |
| CMYK | cmyk(66%, 69%, 0%, 10%) | Print. This is a simple conversion; printers use color profiles for exact results. |
The input box also accepts 3- and 4-digit shorthand HEX (#abc means #aabbcc), rgba() and hsla(), RGB channels as percentages, hue in deg, turn, rad or grad, the CSS space-separated syntax such as hsl(240 100% 50%), oklch() and oklab(), and all 148 CSS color names, such as rebeccapurple.
How the conversions work
Every format is converted to 8-bit RGB first, and the others are calculated from that.
- HEX to RGB: each pair of hex digits is one channel from 00 (0) to FF (255).
- RGB to HSL: scale each channel to 0–1. Lightness is the average of the largest and smallest channel. Saturation is their difference divided by 1 − |2L − 1|. Hue is an angle on the color wheel set by which channel is largest: red near 0°, green near 120°, blue near 240°.
- RGB to HSV: value is the largest channel, and saturation is the difference between largest and smallest divided by the largest.
- RGB to OKLCH: the channels are linearized, converted to the OKLab space with Björn Ottosson's matrices, and then turned into lightness, chroma (distance from gray) and hue angle. An OKLCH color outside the sRGB range is brought into range the CSS Color 4 way, by lowering its chroma.
- RGB to CMYK: K = 1 − the largest channel, then each of C, M and Y is (1 − channel − K) ÷ (1 − K).
Worked example
Take #4F46E5. The pairs 4F, 46 and E5 are 79, 70 and 229, so it is rgb(79, 70, 229). Scaled to 0–1 that is 0.310, 0.275 and 0.898. Blue is largest and green smallest, a difference of 0.624.
- L = (0.898 + 0.275) ÷ 2 = 0.586, so 59%
- S = 0.624 ÷ (1 − |2 × 0.586 − 1|) = 0.754, so 75%
- H = 60 × ((0.310 − 0.275) ÷ 0.624 + 4) = 243.4°, so 243
- K = 1 − 0.898 = 10%, and C = (1 − 0.310 − 0.102) ÷ 0.898 = 66%
The tool shows hsl(243, 75%, 59%), hsv(243, 69%, 90%) and cmyk(66%, 69%, 0%, 10%). Against a white background its contrast ratio is 6.29:1: a pass for AA at both sizes and for AAA large text, but a fail for AAA normal text, which needs 7:1.
Quick contrast check
The contrast section compares your color with the background using the WCAG 2 ratio: AA needs 4.5:1 for normal text and 3:1 for large text, and AAA needs 7:1 and 4.5:1. For example, #767676 on white is 4.54:1, the lightest gray that passes AA. For the formula, user-interface components, transparent colors and suggested fixes, use the color contrast checker.
Common mistakes
- Trusting HSL lightness.
hsl(60, 100%, 50%)(yellow) andhsl(240, 100%, 50%)(blue) have the same L, yet yellow on white is 1.07:1 and blue is 8.59:1. Check the contrast ratio, not the L value. - Expecting exact round trips. HSL and HSV are rounded to whole numbers, so
hsl(243, 75%, 59%)converts to#5048E5, one or two steps away from#4F46E5. Keep the HEX or RGB value as your source of truth. - Sending this CMYK to print. The simple formula ignores ink, paper and ICC profiles. Use it as a starting point and let your print software convert.
Transparency
Alpha is stored in 8 bits in HEX, so rgba(0, 0, 0, 0.5) becomes #00000080, and converting back gives an alpha of 0.502. HSV and CMYK have no alpha, so they describe the solid color only.