Designers, developers and printers all describe colour differently. CSS files use hex codes like #2A9D8F, image editors show RGB sliders, colour pickers think in HSL or HSV, and print shops ask for CMYK. This converter takes a colour in any of those notations and gives you all the others at once, ready to paste into a stylesheet or a design tool.
It also answers the question that usually comes next: can I put text on this colour? The calculator computes the relative luminance defined by WCAG 2.2 and the contrast ratio against white and against black, tells you which of the two reads better, and says which accessibility level (AA or AAA) that contrast reaches.
The conversions follow the algorithms published in the W3C CSS Color Module Level 4, so the HSL and HWB values match what browsers compute. Transparent colours are supported: 4- and 8-digit hex codes (#rgba, #rrggbbaa) and an opacity field for RGB, HSL, HWB and HSV.
How to use this calculator
- Choose the notation you already have in Convert from: HEX, RGB, HSL, HWB, HSV or CMYK.
- Type the code or the channel values. Hex codes work with or without "#", in 3, 4, 6 or 8 digits, in upper or lower case.
- For RGB, HSL, HWB and HSV you can also set an opacity; the hex result then gets two extra digits and RGB becomes rgba().
- Read every other notation in the results, plus the WCAG luminance and the two contrast ratios.
- Open the steps to see how each hex pair becomes a decimal channel.
The formula
Hex to RGB. Each pair of hex digits is one byte: , where A–F stand for 10–15. Short codes double each digit (#3a7 = #33aa77).
RGB to HSL (CSS Color 4). With scaled to 0–1, , :
HSV and HWB share the same hue: , ; whiteness , blackness .
Naive CMYK: , (same for M and Y).
WCAG relative luminance: each channel is linearised, if , otherwise , then
Worked example
Take the teal #2A9D8F.
- Hex pairs: 2A = 2 × 16 + 10 = 42, 9D = 9 × 16 + 13 = 157, 8F = 8 × 16 + 15 = 143, so rgb(42, 157, 143).
- Scaled: r = 0.165, g = 0.616, b = 0.561. Max is g, min is r, so , and : hsl(172.7, 57.8%, 39%).
- The same colour is hwb(172.7 16.5% 38.4%) in HWB, hsv(172.7°, 73.2%, 61.6%) in HSV and cmyk(73.2%, 0%, 8.9%, 38.4%) with the naive CMYK formula.
- Its relative luminance is 0.2659, which gives a contrast of 3.32:1 with white and 6.31:1 with black.
Black text is therefore the better choice on this teal and meets AA for normal text, while white text only reaches the 3:1 large-text level. A darker navy such as #1D3557 reaches 12.35:1 against white, enough for white body text at AAA.
Which notation should you use?
| Notation | Typical use | Range |
|---|---|---|
| HEX | CSS, HTML, brand guidelines, design hand-off | 00–FF per channel |
| RGB / RGBA | CSS, image editors, code (0–255 integers) | 0–255, alpha 0–1 |
| HSL | CSS themes: change lightness to build tints and shades | H 0–360°, S and L 0–100 % |
| HWB | CSS Color 4: mix a pure hue with white and black | H 0–360°, W and B 0–100 % |
| HSV / HSB | Colour pickers in Photoshop, Figma and most apps | H 0–360°, S and V 0–100 % |
| CMYK | Printing (inks): needs a press profile for accuracy | 0–100 % per ink |
HSL and HSV look similar but are not interchangeable: 100 % lightness in HSL is always white, whereas 100 % value in HSV is the brightest version of the hue.
Why the CMYK result is only a starting point
Screens add light (RGB) while ink subtracts it (CMYK), and every press, paper and ink set has its own gamut. The formula used here is the textbook, device-independent conversion: it ignores dot gain and ink limits and always uses as much black as possible. Use it to get a rough idea or to fill a quick mock-up, but for brand colours, ask the printer to convert with the ICC profile of the job (for example FOGRA39 or GRACoL), or pick a Pantone reference.
Frequently asked questions
How do I convert a hex code to RGB by hand?
Split the six digits into three pairs and convert each pair from base 16: the first digit times 16 plus the second, with A = 10 up to F = 15. For example FF = 15 × 16 + 15 = 255.
What do 8-digit hex codes mean?
The last two digits are the alpha channel: 00 is fully transparent and FF fully opaque. #2A9D8F80 is the same teal at 128/255 ≈ 50 % opacity, which CSS writes as rgba(42, 157, 143, 0.502).
What contrast ratio do I need for accessible text?
WCAG 2.2 asks for at least 4.5:1 for normal text and 3:1 for large text (about 24 px, or 18.66 px bold) at level AA, and 7:1 and 4.5:1 at level AAA. Icons and form borders need 3:1. The calculator truncates the ratio instead of rounding it up, so 4.499 never shows as a pass.
Why does my converted colour differ by one unit from another tool?
HSL, HSV and CMYK values are usually rounded to whole numbers, and converting a rounded value back to RGB can land one step away. This tool keeps the exact channel values internally and rounds only the displayed result.
Is RGB to CMYK conversion accurate for printing?
Not exactly. The simple formula gives a reasonable approximation, but real printing depends on the press profile. Use the result as a guide and confirm with a proof or a profile-based conversion.
Sources
- W3C, CSS Color Module Level 4 (hex notation, HSL and HWB conversion)
- W3C, Web Content Accessibility Guidelines (WCAG) 2.2: relative luminance and contrast ratio
- W3C WAI, Understanding Success Criterion 1.4.3: Contrast (Minimum)
- A. R. Smith (1978), Color gamut transform pairs, SIGGRAPH ’78 (HSV model)
Last updated: