DoolityDoolity

Color Code Converter: HEX, RGB, HSL, CMYK

Converts a color between HEX, RGB, HSL, HSV, and CMYK, checks the WCAG 2.x contrast ratio between text and background, and builds tints, shades, and color harmonies.

CMYK is an approximation from a simple formula. The printed color depends on the print shop's color profile (ICC) and must be checked on a proof.

Contrast checker

Text color (the color above)#1E90FF

Contrast ratio⁦3.23⁩:1

  • AA, normal text (4.5:1)Fail
  • AA, large text (3:1)Pass
  • AAA, normal text (7:1)Fail
  • AAA, large text (4.5:1)Fail
  • UI components and graphics (3:1)Pass

Aa 가 あ

The quick brown fox jumps over the lazy dog.

다람쥐 헌 쳇바퀴에 타고파

いろはにほへと ちりぬるを

The first line is large text, 24 px (18 pt). The other lines are normal text, 16 px.

Nearest passing color

Only the HSL lightness changes. The hue, saturation, and transparency stay the same.

  • For ⁦4.50⁩:1#0074E6 · ⁦4.52⁩:1
  • For ⁦7.00⁩:1#0058AD · ⁦7.00⁩:1

Calculated with WCAG 2.x, using the relative luminance defined in WCAG 2.2. This is a calculation only. It does not decide whether a page meets the accessibility rules of any country.

A transparent text color is mixed over the background, and a transparent background is mixed over white, before the ratio is calculated.

Palette

Select a color to make it the base color.

Tints (mixed with white)

Shades (mixed with black)

Complementary (180°)

Analogous (±30°)

Triadic (±120°)

Recent colors

Colors you copy appear here.

Some bright RGB colors, such as vivid blues and greens, cannot be printed exactly with CMYK inks.

CSS color names follow W3C CSS Color Module Level 4. Commercial color sample systems are not included.

Recent colors are saved only in this browser.

How to use the color code converter

  1. Type a color in any field, for example #1E90FF in HEX or a CSS name such as tomato. You can also drag in the color picker.
  2. Read the other formats. They change as you type.
  3. In the contrast checker, enter the background color and look at the AA and AAA badges and the sample text.
  4. If a level fails, select "Use this color" next to a suggested color. To start from a related color, select it in the palette.
  5. Copy the code in the format you need.

What is a color code?

A color code is a text notation for a screen color, such as #1E90FF in HEX or rgb(30, 144, 255) in RGB, that gives the amounts of red, green, and blue light in the sRGB color space.

HEX, RGB, HSL, and HSV describe the same sRGB colors in different ways. HEX and RGB give the three channel values. HSL and HSV give a hue angle with saturation and lightness or brightness. CMYK describes ink coverage on paper, so a screen color has no single exact CMYK value.

How the values are calculated

  • In CSS hex notation, each pair of digits is one channel from 00 to FF (0 to 255). A 3-digit code repeats each digit, so #123 is #112233. An 8-digit code adds alpha, where 00 is fully transparent and FF is fully opaque.
  • In HSL, the hue is an angle on the color wheel: 0° is red, 120° is green, and 240° is blue. A lightness of 50% gives the full color, 100% gives white, and 0% gives black.
  • WCAG 2.2 defines relative luminance as 0.2126 R + 0.7152 G + 0.0722 B, after each sRGB channel is linearized. The contrast ratio is (L1 + 0.05) / (L2 + 0.05), where L1 is the lighter color. It ranges from 1:1 to 21:1.
  • WCAG 2.x asks for 4.5:1 for normal text and 3:1 for large text at level AA, 7:1 and 4.5:1 at level AAA, and 3:1 for user interface components and graphics. Large text is at least 18 pt, or 14 pt bold.
  • This tool converts to CMYK with the simple formula K = 1 − max(R, G, B) and C = (1 − R − K) / (1 − K), and the same for M and Y. It uses no color profile, so the result is only an approximation of real ink amounts.

When to use it

  • Turning a HEX code from a design file into rgb() or hsl() for CSS.
  • Checking whether gray text on a white background reaches WCAG AA before publishing a page.
  • Getting a rough CMYK value to discuss with a print shop before you check a proof.
  • Making lighter and darker steps of a brand color for buttons and backgrounds.

Questions about color codes and contrast

How do I convert HEX to RGB?

Split the code into three pairs and read each pair as a hexadecimal number. For #1E90FF, 1E is 30, 90 is 144, and FF is 255, so the color is rgb(30, 144, 255).

Is the CMYK value accurate for printing?

No. It is an approximation. The printed color depends on the paper, the inks, and the print shop's color profile (ICC profile). Ask the print shop for its color settings and check a proof before printing. Some bright screen colors cannot be printed exactly.

Why does 4.49:1 fail when it is almost 4.5:1?

W3C says not to round the calculated ratio before you compare it with the threshold, so even 4.499:1 does not meet 4.5:1. This tool rounds the ratio down to two decimal places, so a failing ratio never looks like a pass.

Does a pass here mean my website meets accessibility law?

No. The tool only calculates the WCAG 2.x contrast ratio of two colors. Accessibility laws and public-sector guidelines differ by country, may refer to different WCAG versions, and include many other requirements. Check the rules that apply to you.

How is the suggested color chosen?

The tool keeps the hue, saturation, and transparency of the text color and changes only its HSL lightness, in steps of 0.1 percentage points. It picks the passing color with the smallest change. If a lighter and a darker color are equally close, it picks the darker one.

What is the nearest CSS color name?

CSS has 148 named colors, such as tomato and navy. If your color is not exactly one of them, the tool shows the name with the smallest color difference (ΔE) in the CIELAB color space, which follows human color perception more closely than the distance between RGB values.

Is my information sent anywhere?

No. All calculations run in your browser. Recent colors are saved only in this browser.