Color Converter

Convert HEX, RGB and HSL in real time, see HSV and CMYK values and the contrast against white and black, and get a matching palette.

Other notations (click to copy)
Contrast on white: -Contrast on black: -
Tone palette (light β†’ dark, click to copy HEX)
Base Β· analogous (+30Β°) Β· complement (+180Β°) Β· analogous (βˆ’30Β°)

What are HEX, RGB, HSL, HSV and CMYK?

A color code is one color written in a particular coordinate system. Screens create color by mixing red, green and blue light, so every on-screen format ultimately comes from three RGB intensities. Which format you pick depends on what you are trying to do.

The conversion formulas

Divide R, G and B by 255 to get r, g and b between 0 and 1. Let max and min be the largest and smallest of the three, and d = max βˆ’ min.

Worked examples

Example 1: warm gold #C9A961. RGB is (201, 169, 97). Here max = 201/255 = 0.788, min = 97/255 = 0.380 and d = 0.408, so L = (0.788 + 0.380) / 2 β‰ˆ 58% and S = 0.408 / (1 βˆ’ |2 Γ— 0.584 βˆ’ 1|) β‰ˆ 49%. Red is the maximum, so H = 60 Γ— ((169 βˆ’ 97) / 104) β‰ˆ 42Β°. The result is HSL β‰ˆ (42Β°, 49%, 58%), HSV with S β‰ˆ 52% and V β‰ˆ 79%, and CMYK by the simple formula of (0%, 16%, 52%, 21%). Against white its contrast ratio is about 2.25:1, which is too low for body text on a white page, while against black it is about 9.33:1, which is plenty.

Example 2: orange-red #FF5733. RGB (255, 87, 51) gives max = 1, min = 0.2 and d = 0.8, so L = 60% and S = 100%, and H = 60 Γ— ((87 βˆ’ 51) / 204) β‰ˆ 10.6Β°, shown as 11Β°. HSL is about (11Β°, 100%, 60%), HSV (11Β°, 80%, 100%) and CMYK (0%, 66%, 80%, 0%). The contrast against white is about 3.15:1, above the 3:1 threshold for large text but below the 4.5:1 normally required for body text.

Example 3: pure blue #0000FF. HSL is (240Β°, 100%, 50%), HSV (240Β°, 100%, 100%) and CMYK (100%, 100%, 0%, 0%). Its contrast against white is about 8.59:1. It is a good reminder that "100%" means something different in HSL and in HSV.

Reference table: common colors

The values below were computed with the same formulas when this page was built. Paste any HEX value from the table into the converter to compare.

ColorHEXRGBHSL
Black#0000000, 0, 00Β°, 0%, 0%
White#FFFFFF255, 255, 2550Β°, 0%, 100%
Red#FF0000255, 0, 00Β°, 100%, 50%
Green (lime)#00FF000, 255, 0120Β°, 100%, 50%
Blue#0000FF0, 0, 255240Β°, 100%, 50%
Yellow#FFFF00255, 255, 060Β°, 100%, 50%
Cyan#00FFFF0, 255, 255180Β°, 100%, 50%
Magenta#FF00FF255, 0, 255300Β°, 100%, 50%
50% gray#808080128, 128, 1280Β°, 0%, 50%
Orange#FFA500255, 165, 039Β°, 100%, 50%
Warm gold (tool default)#C9A961201, 169, 9742Β°, 49%, 58%

Why is the CMYK value only an approximation?

A screen can only show colors inside its own gamut of light, and a printed sheet can only show what its inks and paper allow, and the two ranges differ a lot. The formula above is a mathematical shortcut between the two systems and knows nothing about real inks. The same CMYK numbers look different on coated and uncoated paper, and the numbers change again once a printer's ICC profile (for example a FOGRA or SWOP family profile) is applied. Very vivid greens, oranges and blues often cannot be reproduced in CMYK at all and print duller than on screen. Use the CMYK shown here only as a rough starting point. For print work, convert in your design software with the profile your printer asks for, and confirm with a proof or a physical swatch book if the color matters.

How the contrast ratio is calculated

The Web Content Accessibility Guidelines (WCAG) judge text legibility by the contrast ratio between text and background. First each channel is linearized: for an sRGB value v between 0 and 1, use v / 12.92 when v is 0.04045 or less, otherwise ((v + 0.055) / 1.055)2.4. Relative luminance is L = 0.2126 R + 0.7152 G + 0.0722 B, and the ratio is (lighter L + 0.05) / (darker L + 0.05). Under WCAG 2.x, level AA asks for at least 4.5:1 for normal body text and 3:1 for large text (roughly 24 px or larger, or 18.7 px or larger in bold). Level AAA asks for 7:1 and 4.5:1 respectively. This tool only shows how your chosen color fares against white and against black. To compare any two colors, use the color contrast checker.

Writing transparency in HEX

CSS accepts eight-digit HEX in the form #RRGGBBAA, where the last pair is the opacity. For an opacity of p percent, convert round(p / 100 Γ— 255) to hexadecimal. For example 50% is 127.5, which rounds to 128, or 80 in hex, so #C9A96180 is the gold above at about half opacity. The same thing can be written as rgb(201 169 97 / 50%), which is usually easier to read.

OpacityAlpha HEXDecimal
100%FF255
90%E6230
80%CC204
70%B3179
60%99153
50%80128
40%66102
30%4D77
20%3351
10%1A26
5%0D13
0%000

This converter accepts three- and six-digit HEX only. If you have an eight-digit value, enter its first six digits.

How the palettes are built

The tone palette keeps your color's hue and saturation and changes only the lightness, to 90, 75, 60, 45, 30 and 15%. The complement adds 180Β° to the hue, and the analogous colors add 30Β° and subtract 30Β° (shown as +330Β°). This is purely mechanical HSL arithmetic, so it does not divide perceived brightness evenly. Yellows look much lighter than blues at the same L. Treat the palette as a starting point and check contrast before using it in an interface. For richer combinations see the color palette generator, and to look up colors that have CSS names, the CSS named colors reference.

Common mistakes and limits

Putting the results to use

  1. Enter the HEX from your design tool and copy the CSS rgb() or hsl() notation.
  2. Convert a brand color to HSL and vary only the lightness to get hover, disabled and background tones.
  3. Check that a candidate text color passes 4.5:1 against white or black, and adjust its lightness if it does not.
  4. For print, take the CMYK approximation as a starting point and convert again with your printer's profile.

If you are curious about hexadecimal itself, try the number base converter; for lengths, weights and other units there is the unit converter; and for gradient code the CSS gradient generator helps.

Frequently Asked Questions

What happens when I click a palette color or a result chip?

Clicking a palette swatch copies its HEX code to the clipboard. Clicking the RGB, HSL, HSV or CMYK chip copies that notation.

Can I paste these colors straight into a design tool?

HEX codes work in Figma, Photoshop, CSS and most other tools. If the tool's color management (sRGB, Display P3 and so on) differs, the color on screen may look slightly different.

Can I type a three-digit HEX code?

Yes. #FA0 is read as #FFAA00. Eight-digit HEX with alpha is not supported, so enter only the first six digits.

Will a CMYK print match what I see on screen?

Not exactly. The CMYK shown here is a mathematical approximation, and real print color depends on ink, paper and profile. Convert with your printer's profile and check a proof.

Why is L = 50% the most vivid color in HSL?

HSL lightness is the average of the largest and smallest channel, so a color with one channel at maximum and another at 0 (such as 255, 0, 0) has L = 50%. Raising L mixes in white and lowering it mixes in black, both of which reduce vividness.

Related tools