One blue, six colour formats, and two numbers that mislead: a short reference
A short reference for the six ways a colour gets written, built around one blue, #2B59F5: four tables and three small scripts. The tables come from running the code below on Node 24, and each example was checked in the C
A short reference for the six ways a colour gets written, built around one blue, #2B59F5: four tables and three small scripts. The tables come from running the code below on Node 24, and each example was checked in the Color Converter. I wrote this with AI help; the quoted rules are from the linked pages as they read on 28 November 2026.
Table 1: one colour, six formats
| Format |
#2B59F5 written that way |
The numbers are |
|---|---|---|
| HEX | #2B59F5 |
three bytes, 00 to FF |
| RGB | rgb(43, 89, 245) |
the same bytes, 0 to 255 |
| HSL | hsl(226.3, 91%, 56.5%) |
hue, saturation, lightness |
| HWB | hwb(226.3 16.9% 3.9%) |
hue, whiteness, blackness |
| OKLCH | oklch(53.82% 0.2378 265.64) |
perceived lightness, chroma, hue |
| CMYK | cmyk(82%, 64%, 0%, 4%) |
ink split, no print profile |
Keep the decimals. Round the HSL to hsl(227 91% 56%) and the converter turns it back into #2955F5, not #2B59F5. Store the hex in your design tokens and derive the rest from it.
The conversions, short enough to read
const hexToRgb = (hex) => {
let h = hex.replace('#', '');
if (h.length <= 4) h = [...h].map((c) => c + c).join(''); // #F53 -> FF5533
const n = (i) => parseInt(h.slice(i, i + 2), 16);
return { r: n(0), g: n(2), b: n(4), a: h.length === 8 ? n(6) / 255 : 1 };
};
function rgbToHsl({ r, g, b }) {
[r, g, b] = [r / 255, g / 255, b / 255];
const max = Math.max(r, g, b), min = Math.min(r, g, b), d = max - min;
const l = (max + min) / 2;
if (d === 0) return { h: 0, s: 0, l };
const h = max === r ? ((g - b) / d) % 6 : max === g ? (b - r) / d + 2 : (r - g) / d + 4;
return { h: (h * 60 + 360) % 360, s: d / (1 - Math.abs(2 * l - 1)), l };
}
const rgbToHwb = (c) => ({
h: rgbToHsl(c).h,
w: Math.min(c.r, c.g, c.b) / 255,
b: 1 - Math.max(c.r, c.g, c.b) / 255,
});
const toLinear = (v) => ((v /= 255) <= 0.04045 ? v / 12.92 : ((v + 0.055) / 1.055) ** 2.4);
function rgbToOklch(c) {
const [r, g, b] = [c.r, c.g, c.b].map(toLinear);
const l = Math.cbrt(0.4122214708 * r + 0.5363325363 * g + 0.0514459929 * b);
const m = Math.cbrt(0.2119034982 * r + 0.6806995451 * g + 0.1073969566 * b);
const s = Math.cbrt(0.0883024619 * r + 0.2817188376 * g + 0.6299787005 * b);
const L = 0.2104542553 * l + 0.793617785 * m - 0.0040720468 * s;
const A = 1.9779984951 * l - 2.428592205 * m + 0.4505937099 * s;
const B = 0.0259040371 * l + 0.7827717662 * m - 0.808675766 * s;
return { l: L, c: Math.hypot(A, B), h: ((Math.atan2(B, A) * 180) / Math.PI + 360) % 360 };
}
function rgbToCmyk({ r, g, b }) {
const k = 1 - Math.max(r, g, b) / 255;
if (k === 1) return { c: 0, m: 0, y: 0, k: 1 };
const f = (v) => (1 - v / 255 - k) / (1 - k);
return { c: f(r), m: f(g), y: f(b), k };
}
const pct = (v) => Math.round(v * 1000) / 10 + '%';
const c = hexToRgb('#2B59F5');
const hsl = rgbToHsl(c), hwb = rgbToHwb(c), ok = rgbToOklch(c), k = rgbToCmyk(c);
console.log(`rgb(${c.r}, ${c.g}, ${c.b})`);
console.log(`hsl(${hsl.h.toFixed(1)}, ${pct(hsl.s)}, ${pct(hsl.l)})`);
console.log(`hwb(${hwb.h.toFixed(1)} ${pct(hwb.w)} ${pct(hwb.b)})`);
console.log(`oklch(${(ok.l * 100).toFixed(2)}% ${ok.c.toFixed(4)} ${ok.h.toFixed(2)})`);
console.log(`cmyk(${[k.c, k.m, k.y, k.k].map((v) => Math.round(v * 100) + '%').join(', ')})`);
It prints the RGB to CMYK rows of Table 1 exactly as shown. Two details sit in hexToRgb. A three-digit hex doubles each digit, so #F53 is #FF5533, and an eight-digit hex carries alpha in its last pair, so #FF000080 has alpha 128/255, shown as 0.502. The CMYK formula assumes perfect inks: a starting point for the printer, not a final value.
Table 2: the first number that misleads, HSL lightness
Each colour below is full saturation at exactly 50% HSL lightness. Same functions:
for (const hex of ['#FFFF00', '#00FFFF', '#00FF00', '#FF00FF', '#FF0000', '#0000FF']) {
const c = hexToRgb(hex);
console.log(hex, 'HSL L', pct(rgbToHsl(c).l), ' OKLCH L', (rgbToOklch(c).l * 100).toFixed(1) + '%');
}
| Hex | HSL lightness | OKLCH lightness |
|---|---|---|
#FFFF00 |
50% | 96.8% |
#00FFFF |
50% | 90.5% |
#00FF00 |
50% | 86.6% |
#FF00FF |
50% | 70.2% |
#FF0000 |
50% | 62.8% |
#0000FF |
50% | 45.2% |
One HSL number, a spread from 45% to 97% in how light the colour looks. In OKLCH equal lightness looks equally light across hues, so palettes and hover states made by stepping L stay even, and every modern browser accepts oklch().
OKLCH can also name colours an sRGB screen cannot show. oklch(70% 0.4 150) comes back from the converter with chroma 0.1928 (#00BE58), lightness and hue kept, and a note saying so.
Table 3: the WCAG 2 levels
| Level | Normal text | Large text (24 px, or about 19 px bold) |
|---|---|---|
| AA | 4.5:1 | 3:1 |
| AAA | 7:1 | 4.5:1 |
Table 4: the second number that misleads, a rounded ratio
The WCAG 2 ratio is (lighter luminance + 0.05) / (darker luminance + 0.05):
const luminance = (c) => 0.2126 * toLinear(c.r) + 0.7152 * toLinear(c.g) + 0.0722 * toLinear(c.b);
const contrast = (fg, bg) => {
const [hi, lo] = [luminance(fg), luminance(bg)].sort((x, y) => y - x);
return (hi + 0.05) / (lo + 0.05);
};
const white = hexToRgb('#FFF');
for (const hex of ['#767676', '#777777', '#457BAA', '#09F']) {
const r = contrast(hexToRgb(hex), white);
console.log(hex, r.toFixed(5), r.toFixed(2), (Math.floor(r * 100) / 100).toFixed(2),
r >= 4.5 ? 'AA' : '-', r >= 3 ? 'AA-large' : '-');
}
| Text on white | Exact ratio | toFixed(2) |
Rounded down | AA normal | AA large |
|---|---|---|---|---|---|
#767676 |
4.54222 | 4.54 | 4.54 | pass | pass |
#777777 |
4.47809 | 4.48 | 4.47 | fail | pass |
#457BAA |
4.49999 | 4.50 | 4.49 | fail | pass |
#09F |
2.99979 | 3.00 | 2.99 | fail | fail |
#457BAA and #09F (the short form on the HEX to RGB page) both print as the threshold with ordinary rounding, and both fail, because the comparison uses the exact ratio. The Contrast Checker rounds down instead and shows 4.49:1 and 2.99:1, each marked fail. In a lint script of your own, compare the number with >= 4.5, never the formatted string.
Translucent text is blended over the background first, so #FF000080 on white is measured as the pink you actually see: 2.44:1.
Missing a row you rely on? Leave it in the comments and I will check it the same way.
Originally published by Dev.to WebDev. Aggregated on AIWithGhost for educational purposes — full credit and traffic to the original publisher.