HomeUnit Conversion › Color Converter

Color Converter

Parses a colour given as HEX, RGB or HSL and returns it in HEX, RGB, HSL, HSV and CMYK notation, plus its sRGB relative luminance and WCAG 2 contrast ratios against white and black with the conformance level for text.

When to use

You need the same colour in another notation (e.g. HEX to HSL for CSS, RGB to CMYK for print) or want to check whether text in this colour meets WCAG AA/AAA contrast on a white or black background.

Do not use when: You need the contrast between two arbitrary colours (run this tool for each and divide (L1 + 0.05)/(L2 + 0.05)), colour-managed conversions (Lab, wide-gamut, ICC profiles) or print-accurate CMYK for a specific press.

Formula

HSL: L = (max + min)/2, S = (max − min)/(1 − |2L − 1|), H from the dominant channel (60° sectors); HSV: V = max, S = (max − min)/max; CMYK: K = 1 − max, C = (1 − R − K)/(1 − K) etc.; luminance Y = 0.2126·R_lin + 0.7152·G_lin + 0.0722·B_lin with c_lin = c/12.92 if c ≤ 0.04045 else ((c + 0.055)/1.055)^2.4; contrast = (Y_lighter + 0.05)/(Y_darker + 0.05)

Channels are sRGB 8-bit; HSL/HSV use the standard hexcone formulas, CMYK the simple complement (real print profiles differ). WCAG 2 thresholds: 4.5:1 AA and 7:1 AAA for normal text, 3:1 AA for large text (≥ 18 pt or 14 pt bold) and UI components.

Inputs

ParameterTypeUnitRequiredDescription
colorstringyesColour as HEX (#FF8800 or F80), rgb(255, 136, 0) / 255,136,0, or hsl(32, 100%, 50%). Bare comma-separated numbers are read as RGB unless format says otherwise.
formatenum: auto | hex | rgb | hsldefault autoHow to interpret the colour string; auto detects #hex, rgb(...) and hsl(...) prefixes.

Outputs

OutputTypeUnitDescription
hexstring#RRGGBB, upper case.
rgbstringCSS rgb() notation with 0–255 integers.
redintegerRed component 0–255.
greenintegerGreen component 0–255.
blueintegerBlue component 0–255.
hslstringCSS hsl() notation (hue in degrees, saturation and lightness in %).
hue_degnumber°Hue angle 0–360° (shared by HSL and HSV).
hsl_saturation_percentnumber%Saturation in the HSL model.
lightness_percentnumber%HSL lightness.
hsvstringHue, saturation and value (brightness) as used by many colour pickers.
hsv_saturation_percentnumber%Saturation in the HSV model.
value_percentnumber%HSV value = max(R, G, B).
cmykstringNaive CMYK percentages (no ICC profile).
relative_luminancenumberWCAG sRGB relative luminance Y (0 = black, 1 = white).
contrast_ratio_whitenumberWCAG contrast ratio against #FFFFFF (1 to 21).
contrast_ratio_blacknumberWCAG contrast ratio against #000000.
wcag_on_whitestringWCAG 2 level for this colour as text on a white background.
wcag_on_blackstringWCAG 2 level for this colour as text on a black background.
best_text_colorstringblack or white, whichever has the higher contrast when this colour is the background.

Example

#FF8800: {"color":"#FF8800"}{"hex":"#FF8800","rgb":"rgb(255, 136, 0)","red":255,"green":136,"blue":0,"hsl":"hsl(32, 100%, 50%)","hue_deg":32,"hsl_saturation_percent":100,"lightness_percent":50,"hsv":"hsv(32, 100%, 100%)","cmyk":"cmyk(0%, 47%, 100%, 0%)","relative_luminance":0.3887,"contrast_ratio_white":2.39,"contrast_ratio_black":8.77,"best_text_color":"black","wcag_on_white":"Fails (below 3:1)"}

hsl(210, 50%, 40%): {"color":"hsl(210, 50%, 40%)"}{"hex":"#336699","rgb":"rgb(51, 102, 153)","hsv":"hsv(210, 67%, 60%)","hsv_saturation_percent":66.7,"value_percent":60,"relative_luminance":0.1251,"contrast_ratio_white":6,"contrast_ratio_black":3.5,"wcag_on_white":"AA for normal text, AAA for large text (4.5:1 to 7:1)","best_text_color":"white"}

GET https://tttkmbb.com/api/v1/calculate/color-converter?color=%23FF8800

Machine access

Sources

FAQ

Why is the CMYK different from my design software?

Software converts through ICC profiles (e.g. US Web Coated SWOP) that model real inks; the naive complement formula here is the one used by most online converters and gives an approximation only.

Which WCAG level do I need?

Level AA (WCAG 2 success criterion 1.4.3) requires 4.5:1 for normal text and 3:1 for large text; AAA (1.4.6) requires 7:1 and 4.5:1. Non-text UI components need 3:1 (1.4.11).

Does the converter accept alpha?

No. Use 3- or 6-digit hex, rgb() or hsl() without an alpha channel; transparency changes the effective contrast depending on what lies underneath.

Related calculators