Colour Code Converter
Colour Code Converter Tool
How to Use the Colour Code Converter
Pick or paste a colour
Use the colour picker, or paste a HEX, rgb(), hsl(), hsb() or cmyk() value into any of the five editable fields. The tool recognises the format by its prefix (a bare string of 3, 4, 6 or 8 hex digits reads as HEX), and says so if it cannot read what you typed. The Lab and OKLCH rows are output only.
All formats update live
Change any input and every other format updates instantly. The single source-of-truth state means no out-of-sync values.
Adjust the alpha
Slide the alpha control to add transparency. The HEX, RGB, HSL, Lab and OKLCH outputs carry the alpha channel automatically; HSB and CMYK have none.
Check accessibility
WCAG AA and AAA badges show whether the colour meets the contrast thresholds against a white and a black background. Below 100% alpha, the colour is graded as it appears: blended onto each background first.
About Colour Format Conversion
Modern design and development demand fluency across multiple colour formats — each describes the same colour but with different trade-offs. HEX codes (#FF5733) are the lingua franca of the web because they're compact, copy-pasteable, and supported in every CSS spec since the beginning. RGB and RGBA spell out red, green, and blue channels (0–255) plus optional alpha for transparency — required when you need translucent overlays in CSS. HSL (Hue, Saturation, Lightness) lets you lighten or darken a colour by adjusting a single value, which is why design system tokens often use it. HSB/HSV (Hue, Saturation, Brightness/Value) is the model behind many design-tool colour pickers. CMYK is the process-colour model of four-colour printing. The two read-only rows add CIE Lab and OKLCH, the perceptual spaces CSS Color Level 4 brought to the web as lab() and oklch().
The reason this converter exists is that every format hides traps. HEX shortcodes (#F53) only work for specific 12-bit values. RGB → HSL conversion isn't perceptually uniform, so "lightness 50%" of red doesn't visually match "lightness 50%" of blue. A CMYK number has no single screen colour: how it prints depends on the press, the paper and the inks, and CSS Color Level 5 shows one CMYK value giving three visibly different colours under two press profiles and the naive formula. Knowing which format to use when, and how to convert without losing data, is a baseline skill for anyone who touches design systems, brand guidelines, or print collateral.
"There is no such thing as 'the' colour blue — only the blue a monitor renders, the blue a press prints and the blue a phone shows. Conversion is where the problem starts, not where it ends."
When to use which format
For web CSS, use HEX (#FF5733) for opaque solid colours — it's the shortest and works everywhere. Use RGBA (rgba(255, 87, 51, 0.5)) when you need transparency for overlays, modals, or fade-out effects. Use HSL (hsl(11, 100%, 60%)) in design system tokens where you want to programmatically generate lighter and darker variants — increment the lightness value in steps for shade ladders. For design tool exchange, HSB/HSV is most likely what Figma, Sketch, or your wireframing tool exposes — knowing the conversion makes copying a colour from Figma to CSS painless. For print briefs to commercial printers in Singapore, Malaysia, or Indonesia, send CMYK — and ask the printer for its ICC profile, because the CMYK numbers here come from a naive formula, not a press separation.
Why the WCAG contrast ratio matters
The contrast-ratio panel in this tool calculates the WCAG relative-luminance contrast ratio between your colour and white, and between your colour and black (the formula is the same in WCAG 2.1 and 2.2). WCAG AA requires 4.5:1 between body text and its background. AAA (the stricter level) requires 7:1. Large text has lower bars — 3:1 for AA, 4.5:1 for AAA — and "large" is measured in points: at least 18 pt, or 14 pt bold, which is about 24 px, or 18.7 px bold, in CSS — or a size that would be equivalent for Chinese, Japanese and Korean fonts, which WCAG allows for separately. The tool compares the unrounded ratio, as W3C's guidance says (4.499:1 does not meet 4.5:1), so where two decimals would print a threshold the colour misses, it prints more: #006BFB on black shows 4.496 : 1, not 4.50. A translucent colour is graded after it is blended onto the background, because that blend is what a reader sees: #FF5733 at 50% alpha on white is #FFAB99, 1.82 : 1. Singapore's Digital Service Standards include accessibility based on WCAG principles, and the Government has said it plans to make all high-traffic government websites accessible by 2030; in the EU, EN 301 549 — the harmonised standard under the Web Accessibility Directive for public-sector sites — reflects WCAG 2.1. Conversion plus contrast checking in one place is the single most useful workflow for accessibility-aware design.
This converter keeps one internal RGBA value (0–255 per channel, plus alpha) and re-derives every other format from it, so changing one field updates all the others and repeated edits never drift. Typing into the HSL, HSB or CMYK field is a different matter: those fields hold whole numbers, so a colour written that way and read back can move. Across all 16,777,216 8-bit colours, the whole-number round trip lands up to 5 steps away on a channel through HSL, 3 through HSB and 2 through CMYK; only about one colour in nine comes back exact through HSL. hsb(18, 82%, 91%) gives 232, 99, 42, not the 232, 98, 42 that produced it. The Lab row follows CSS Color Level 4 exactly, D50 white point included, which is why CSS lab() values differ slightly from the D65 Lab some design tools show. Everything runs in your browser — your colours are never sent to any server. Suitable for confidential brand work and competitive launches.
HEX is RGB in disguise, and shortcodes double each digit
HEX is just RGB in disguise. #FF5733 is 255, 87, 51 — each pair of hex digits is one byte (0–255). The hash prefix is decorative; CSS requires it but the colour values are pure RGB.
HEX shortcodes have a catch. #F53 expands to #FF5533, not #F05030. Each digit doubles. So shortcodes only represent 12-bit colours (4096 values), not the full 16M.
HSL vs HSB confusion is universal. CSS uses HSL natively; many design-tool colour pickers offer HSB. The two are NOT interchangeable: 50% lightness in HSL ≠ 50% brightness in HSB.
A CMYK preview is only as good as its profile. The same CMYK number prints differently on different presses, papers and inks, so its screen colour depends on the profile used. Part of a press's range also falls outside sRGB: CSS Color Level 5 puts a FOGRA39 90/0/90/0 green outside sRGB but inside display-p3. The CMYK here is the naive formula, with no profile.
WCAG AA requires 4.5:1. Body text must have a 4.5:1 contrast ratio against its background. Large text — at least 18 point, or 14 point bold (about 24 px, or 18.7 px bold) — drops to 3:1. AAA bumps these to 7:1 and 4.5:1.
Accessibility is becoming a floor, not a feature. Singapore's Digital Service Standards include accessibility based on WCAG principles, and the Government has said it plans to make all high-traffic government websites accessible by 2030; the EU's EN 301 549, harmonised under the Web Accessibility Directive, reflects WCAG 2.1.
8-digit HEX includes alpha. #FF5733CC is #FF5733 with 80% opacity (CC = 204/255). Supported in CSS since Chrome 62, Firefox 49 and Safari 10.
OKLCH is built for perception. CSS Color Module Level 4 added OKLCH, designed so that equal steps in lightness look like roughly equal steps whatever the hue. HSL cannot do that: pure blue and pure yellow both sit at 50% HSL lightness, yet their CSS lab() lightness is 29.6 and 97.6.
Named colours have history. CSS Color Level 4 lists 148 named colours like tomato, cornflowerblue, papayawhip. Sixteen came from the VGA palette; most of the rest from one version of the X11 colour system used on Unix, by way of SVG. rebeccapurple is the one Level 4 itself added.
Everything here is local. Your colours never leave your browser: no request the page makes carries a colour you convert. Safe for confidential brand work and competitive launches.
Frequently Asked Questions
-
Both describe colour with three values (hue, saturation, lightness/brightness), but the lightness axis behaves differently. In HSL, 50% lightness is the pure hue and 100% is white; in HSB, 100% brightness at full saturation is the pure hue and 0% is black. CSS uses HSL natively; many design-tool pickers offer HSB. Always convert deliberately — they are not interchangeable.
-
Alpha is the transparency component, ranging from 0 (fully transparent — invisible) to 1 (fully opaque — solid). RGBA and HSLA explicitly include it as a fourth value:
rgba(255, 87, 51, 0.5). HEX supports alpha via the 8-digit form:#FF573380(the last two digits are alpha, where 80 hex = 128 decimal ≈ 50%). -
It's the luminance ratio between two colours, ranging from 1:1 (identical) to 21:1 (black on white). WCAG accessibility guidelines require minimum ratios: AA = 4.5:1 for body text, 3:1 for large text (at least 18 point, or 14 point bold — about 24 px, or 18.7 px bold). AAA bumps these to 7:1 and 4.5:1. The ratio is compared unrounded, so 4.499:1 does not meet 4.5:1. A translucent colour is graded after blending onto the background.
-
For approximate work like web mockups, blog posts about brand colours, and quick previews — yes. For colour-critical commercial print (offset printing, packaging, branded merchandise) — no. CMYK accuracy depends on the specific printer's ICC profile, paper stock, and ink set. Always export from Adobe Illustrator or InDesign with the printer's profile applied for final artwork.
-
No. Everything runs in your browser. We don't log inputs, store conversion history, or send analytics on what you convert. Verifiable in DevTools: the page still sends its usual page-view beacons, but none of them contains a colour you entered. Safe for confidential brand work, competitive product launches, and any colour data you'd rather keep private.
-
HEX shortcodes (
#F53) expand by duplicating each digit.#F53becomes#FF5533, NOT#F05030. This means shortcodes only represent 12-bit colours (4096 possible values), missing 99.97% of the full 24-bit colour range (16.7 million values). Always use full 6-digit HEX for precise colours. -
Standard HEX (
#FF5733) is 6 digits representing red, green, and blue (8 bits each). 8-digit HEX (#FF5733CC) adds an alpha channel as the last two digits (CC = 204/255 = 80% opacity). Supported in CSS since Chrome 62, Firefox 49 and Safari 10, and in Edge since it moved to Chromium. Use it when you need transparent solid colours in CSS without writing the longer rgba() form. -
OKLCH (Lightness, Chroma, Hue) is a colour space added to CSS in Color Module Level 4, designed so that equal lightness steps look roughly equal whatever the hue — which HSL does not manage. Useful for generating consistent design-system shade ladders; the read-only OKLCH row above gives the oklch() value of your colour. Supported since Safari 15.4, Chrome 111 and Firefox 113. Worth learning if you're building a serious design system; overkill for one-off colour adjustments.
-
Screens differ in colour gamut and calibration, so the same value can look more or less saturated from one device to the next. A plain CSS colour such as
rgb()or a HEX code is sRGB; a wide-gamut screen shows it as sRGB, and an uncalibrated one may not. Check important colours on the devices your readers use, not only on your own.
Method & sources
How it computes
One RGBA state drives every field. HEX per CSS Color 4 §5.2; HSL by its §7 algorithms; HSB/HSV by Smith's hexcone; CMYK by the naive K = 1 − max(R, G, B) of CSS Color 5, no ICC profile; lab() (D50) and oklch() with the §10 matrices. Contrast per WCAG 2.2, (L1 + 0.05) ÷ (L2 + 0.05), on the colour as seen: alpha is blended onto white and black first, and the printed ratio is never rounded onto a threshold the unrounded ratio misses.
What this tool implements
- Colour syntax and the HSL conversion follow W3C CSS Color Module Level 4 (Candidate Recommendation Draft, 3 November 2026): #RGB, #RGBA, #RRGGBB, #RRGGBBAA with shorthand doubling each digit (§5.2), and the spec's own hslToRgb / rgbToHsl algorithms (§7.1, §7.2). Five- and seven-digit hex is not a colour and is refused. Every editable field reads any of HEX, rgb(), hsl(), hsb()/hsv() or cmyk(), recognised by its prefix.
- CSS lab() is CIE Lab against a D50 white (§9: "The illuminant is D50 white"): sRGB is decoded with the sRGB transfer function, taken to XYZ with the spec's D65 matrix, Bradford-adapted to D50 and converted with ε = 216/24389, κ = 24389/27. oklch() uses the spec's 64-bit XYZ↔LMS matrices. The tests pin the spec's own printed examples — sRGB blue lab(29.567% 68.298 -112.0294), sRGB yellow lab(97.607% -15.753 93.388) — so a D65 white fails them.
- Contrast per WCAG 2.2 definitions: relative luminance with the 0.04045 linearisation threshold, contrast ratio (L1 + 0.05) / (L2 + 0.05); AA 4.5:1, AAA 7:1, large text 3:1 and 4.5:1, where large scale is at least 18 point or 14 point bold, or the equivalent size for CJK fonts.
- A colour with alpha below 1 is graded as it appears: composited source-over onto each opaque background (a·c + (1 − a)·b per channel, rounded to the byte) before the ratio is computed. #FF5733 at 50% on white is #FFAB99, 1.82:1.
- The verdict compares the unrounded ratio, as W3C's Understanding SC 1.4.3 says ("4.499:1 would not meet the 4.5:1 threshold"). The printed ratio uses two decimals unless that would show a threshold the ratio misses; then it adds decimals (#006BFB on black prints 4.496, not 4.50).
- HSB/HSV follows Smith's 1978 hexcone. Hue prints in whole degrees in [0, 360) and saturation, lightness, brightness and CMYK in whole percent, so a value read back from those fields can move: measured over all 16,777,216 8-bit colours, by up to 5 steps on a channel through HSL, 3 through HSB and 2 through CMYK.
- Corrected 2026-11-04: contrast ignored alpha (graded the opaque colour) → graded after blending onto each background; the printed ratio could round up onto a threshold the badge said was missed → never does; "the tool detects the format automatically" → it now does, in every editable field; "a monitor physically cannot display the CMYK gamut" → part of a press's range lies outside sRGB and a preview is only as good as its profile; "one step away" → measured maxima 5/3/2; FAQ giving a legal view on using colour values removed; MDDI cited by title, not linked.
Show 1 more
- CMYK is the naive formula of CSS Color Level 5 §6.1, which that draft calls "necessarily approximate"; real print separation needs the printer's ICC profile, and the page says so.
Sources
- W3C. CSS Color Module Level 4, Candidate Recommendation Draft, 3 November 2026 — §5.2 hex notation, §6.1 named colours (148), §7 HSL conversion, §9 Lab (D50) and §10 sample conversion code: https://www.w3.org/TR/css-color-4/
- W3C. CSS Color Module Level 5, Working Draft, 29 October 2026 — §6.1 naive CMYK conversion and the SWOP/FOGRA39 profile examples: https://www.w3.org/TR/css-color-5/
- W3C. Web Content Accessibility Guidelines (WCAG) 2.2 — SC 1.4.3, SC 1.4.6 and the definitions of contrast ratio, relative luminance and large scale (text): https://www.w3.org/TR/WCAG22/
- W3C WAI. Understanding SC 1.4.3: Contrast (Minimum), WCAG 2.2 — computed ratios are not rounded: https://www.w3.org/WAI/WCAG22/Understanding/contrast-minimum.html
- Smith AR. Color gamut transform pairs. ACM SIGGRAPH Computer Graphics 1978;12(3):12-19. (the HSV hexcone model)
- ETSI. EN 301 549 V3.2.1 (2021-03), Accessibility requirements for ICT products and services — harmonised under Directive 2016/2102; reflects WCAG 2.1: https://www.etsi.org/deliver/etsi_en/301500_301599/301549/03.02.0…
- GovTech Singapore. Digital Service Standards — Accessibility (WCAG principles): https://www.tech.gov.sg/products-and-services/for-government-agen…
- Ministry of Digital Development and Information (Singapore). Response to Parliamentary Question on ensuring high-traffic Government websites conform to WCAG, 12 November 2024.
Show 1 more
- MDN browser-compat-data, css/types/color.json — oklch (Chrome 111, Firefox 113, Safari 15.4) and alpha hex notation (Chrome 62, Firefox 49, Safari 10): https://github.com/mdn/browser-compat-data/blob/main/css/types/co…
What can make this go out of date
- None at runtime; every conversion runs in the browser and nothing is sent anywhere.