Skip to content

Color Converter & Contrast Checker

Convert colours between HEX, RGB, HSL, HSV and CMYK, and check text contrast against WCAG 2.2 AA and AAA, with a suggested accessible colour when it fails.

Calculator Details

Contrast ratio:6.70:1See results ↓

HEX (#1d4ed8 or #abc), rgb(29, 78, 216), hsl(224, 76%, 48%) or cmyk(87%, 64%, 0%, 15%). Used as the text colour.

The colour behind the text, in any of the same formats, for the WCAG contrast check.

Your Results

Contrast ratio: 6.70:1

Contrast ratio

6.70:1

Passes AA for all text

Preview

Normal text: the quick brown fox jumps over the lazy dog.

Large text (24 px)

Bold large text (18.66 px)

WCAG 2.2

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

#1d4ed8 (rgb(29, 78, 216)) on #ffffff has a contrast ratio of 6.70:1 and passes WCAG AA for all text (AAA for large text).

Compare scenarios

Save these inputs as a scenario, change them, and compare the results side by side.

Loading, available in a moment

Detailed Breakdown

#1d4ed8 in every format
FormatValue
HEX#1d4ed8
RGBrgb(29, 78, 216)
HSLhsl(224, 76.3%, 48%)
HSV / HSBhsv(224, 86.6%, 84.7%)
CMYK (approximate)cmyk(87%, 64%, 0%, 15%)
Relative luminance0.1067
Background luminance (#ffffff)1

CMYK is a device-independent approximation; print colours depend on the press profile.

How This Calculator Works

How the Contrast Is Calculated

Each channel: c = value ÷ 255; linear = c ÷ 12.92 if c ≤ 0.04045, else ((c + 0.055) ÷ 1.055)^2.4
Relative luminance L = 0.2126 R + 0.7152 G + 0.0722 B
Contrast ratio = (L lighter + 0.05) ÷ (L darker + 0.05)
Colour #1d4ed8 = rgb(29, 78, 216) → L = 0.1067
Background #ffffff = rgb(255, 255, 255) → L = 1
Ratio = (1 + 0.05) ÷ (0.1067 + 0.05) = 6.702 → 6.70:1
HEX #1d4ed8 = 29, 78, 216 (base 16 → base 10)
HSL: hue 224°, saturation 76.3%, lightness 48% (CSS Color 4)
CMYK: K = 1 − max(29, 78, 216) ÷ 255 = 15%; C, M, Y = (1 − channel − K) ÷ (1 − K) = 87%, 64%, 0%

Pass or fail uses the exact ratio, never a rounded one, as WCAG requires; the ratio shown is rounded down. The luminance values above are rounded to four places, so recomputing the ratio from them can differ in the last digit.

Frequently Asked Questions

How do I convert HEX to RGB?

Split the six hex digits into three pairs and convert each pair from base 16 to base 10. #1D4ED8 is 1D, 4E and D8, which are 1×16 + 13 = 29, 4×16 + 14 = 78 and 13×16 + 8 = 216, so rgb(29, 78, 216). A three-digit shorthand doubles each digit: #ABC is #AABBCC.

What is the WCAG contrast ratio?

It compares the relative luminance of the lighter colour (L1) and the darker one (L2): (L1 + 0.05) ÷ (L2 + 0.05). It runs from 1:1 (identical colours) to 21:1 (black on white). Relative luminance weights the linearised red, green and blue channels by 0.2126, 0.7152 and 0.0722, because the eye is most sensitive to green and least to blue.

What contrast ratio do I need?

WCAG 2.2 Level AA asks for at least 4.5:1 for normal text and 3:1 for large text (24 CSS px regular or about 18.66 px bold and up). Level AAA asks for 7:1 and 4.5:1. Icons, input borders, focus indicators and other user-interface parts need 3:1 against what is next to them (Success Criterion 1.4.11). Logos and purely decorative text are exempt.

Why does 4.48:1 fail when it rounds to 4.5?

WCAG says the ratio must not be rounded up when checking a threshold, so 4.499:1 fails 4.5:1. The calculator decides pass or fail on the exact ratio and shows it rounded down to two decimals, so a ratio that displays as 4.50 really is at least 4.5. The grey #777777 on white is 4.48:1 and fails; #767676 is 4.54:1 and passes.

What is the difference between HSL and HSV?

Both describe a colour by hue (the angle on the colour wheel, 0–360°) and saturation, but the third value differs. HSL’s lightness puts pure colours at 50% and white at 100%; HSV’s value puts pure colours at 100%, with white at 100% value and 0% saturation. CSS uses HSL (hsl()); many design tools’ colour pickers use HSV, sometimes called HSB.

Is the CMYK conversion accurate for printing?

It is the standard device-independent formula (K = 1 − the largest of R, G and B, then C, M and Y from what is left), useful for a rough idea. Real print colours depend on the printer, ink, paper and colour profile (for example FOGRA39 or GRACoL), and many bright screen colours cannot be printed at all. For print work, convert with your design software using the printer’s ICC profile.

How does the suggested accessible colour work?

When a colour fails 4.5:1 for normal text, the calculator keeps its hue and saturation and moves its HSL lightness up or down in 0.1% steps until the contrast with the background passes, then shows the closest one. Your brand colour usually only needs to get a little darker (on light backgrounds) or lighter (on dark ones). If no lightness passes, no suggestion is shown; change the background instead.

Which colour formats can I type in?

HEX with or without the # (#1d4ed8, 1d4ed8, #abc), rgb(29, 78, 216), hsl(224, 76%, 48%) and cmyk(87%, 64%, 0%, 15%). Commas or spaces both work, as in modern CSS. Colours with transparency (#rrggbbaa, rgba with an alpha below 1) are not supported, because their contrast depends on whatever is behind them.

Contrast per WCAG 2.2 (relative luminance, contrast ratio, SC 1.4.3, 1.4.6 and 1.4.11); conversions per CSS Color Module Level 4 in the sRGB colour space. CMYK uses the simple formula without an ICC profile, so print results will differ. Transparency, wide-gamut colours (Display P3), font-weight and anti-aliasing effects and the draft APCA method of WCAG 3 are not included.

Color Converter and Contrast Checker: HEX, RGB, HSL, CMYK and WCAG

By FindMySum · Last reviewed

A color converter translates one colour between the notations designers and developers use: HEX codes in CSS, RGB triples, HSL and HSV values from colour pickers and CMYK percentages for print. This one also checks the colour against a background using the contrast formula from the Web Content Accessibility Guidelines (WCAG) 2.2, and suggests the nearest colour that passes when yours does not. This article explains how each format works, how the conversions are done, how the contrast ratio is calculated and how to read the pass and fail results.

RGB and HEX: the same numbers in two bases

Screens make colour by mixing red, green and blue light. In the sRGB colour space used on the web, each channel is a whole number from 0 (off) to 255 (full), so rgb(29, 78, 216) is a little red, some green and a lot of blue.

A HEX code writes the same three numbers in base 16, two digits each. In #1d4ed8, 1d is 1 × 16 + 13 = 29, 4e is 4 × 16 + 14 = 78 and d8 is 13 × 16 + 8 = 216. Converting back is the reverse. A three-digit shorthand repeats each digit, so #abc is #aabbcc. Because the conversion is exact in both directions, HEX and RGB never lose information.

HSL and HSV: colours by hue

HSL describes the same colour as a hue angle on the colour wheel (0° red, 120° green, 240° blue), a saturation and a lightness. It is easier to reason about: keep the hue and lower the lightness for a darker shade, or reduce the saturation for a muted one. CSS supports it directly with hsl(). The calculator follows the CSS Color Module Level 4 algorithm: lightness is the average of the largest and smallest channel, and saturation is the spread between them relative to how far the lightness sits from black or white.

HSV (also called HSB) uses the same hue but a different second and third value. Value is simply the largest channel, so every pure colour has a value of 100%, which matches the square-and-slider pickers in many design tools. Converting to HSL or HSV involves rounding, so a round trip back to RGB can be off by one in a channel.

CMYK: a rough guide for print

Printers subtract light with cyan, magenta, yellow and black ink. The simple conversion sets black first, K = 1 − (largest channel ÷ 255), then works out how much of each coloured ink is needed for the rest: C = (1 − R − K) ÷ (1 − K), and the same for M and Y. That gives a reasonable starting point, but real printed colour depends on the press, ink and paper, described by an ICC colour profile. Bright screen colours such as vivid blues and greens often fall outside what ink can reproduce, so use your design software's profile-based conversion for anything going to a printer.

How contrast is measured

WCAG compares colours by relative luminance, a measure of how bright a colour looks to the eye, from 0 for black to 1 for white. First, each channel is divided by 255 and converted from the sRGB curve to linear light: values up to 0.04045 are divided by 12.92, and higher values become ((c + 0.055) ÷ 1.055) raised to the power 2.4. Then the channels are weighted by how sensitive the eye is to each: L = 0.2126 R + 0.7152 G + 0.0722 B. Green counts almost ten times as much as blue, which is why pure blue text looks dark even though one channel is at full strength.

The contrast ratio puts the lighter luminance over the darker, each with 0.05 added to model ambient light reflecting off the screen:

contrast ratio = (L lighter + 0.05) ÷ (L darker + 0.05)

It ranges from 1:1 for identical colours to 21:1 for black on white.

Worked example with the default colours

The calculator opens with #1d4ed8, a strong blue, on white.

  1. RGB: 29, 78 and 216, which as fractions are 0.1137, 0.3059 and 0.8471.
  2. Linearised: 0.0123, 0.0762 and 0.6867.
  3. Relative luminance: 0.2126 × 0.0123 + 0.7152 × 0.0762 + 0.0722 × 0.6867 = 0.1067.
  4. White has a luminance of 1, so the ratio is (1 + 0.05) ÷ (0.1067 + 0.05) = 6.70:1.

That passes Level AA for normal text (4.5:1) and large text (3:1) and Level AAA for large text (4.5:1), but not AAA for normal text, which needs 7:1. The same colour converts to hsl(224, 76.3%, 48%), hsv(224, 86.6%, 84.7%) and roughly cmyk(87%, 64%, 0%, 15%).

Reading the results

WCAG 2.2 sets several thresholds. Success Criterion 1.4.3 (Level AA) needs 4.5:1 for normal text and 3:1 for large text, meaning at least 24 CSS pixels regular or about 18.66 pixels bold. Criterion 1.4.6 (AAA) raises those to 7:1 and 4.5:1. Criterion 1.4.11 needs 3:1 for the visual parts of controls, such as input borders, focus rings and icons that carry meaning.

WCAG is explicit that ratios are not rounded when testing: 4.499:1 fails 4.5:1. The calculator decides pass and fail on the exact value and displays the ratio rounded down, so the familiar grey #777777 on white shows 4.47:1 and fails, while #767676 shows 4.54:1 and passes.

When a colour fails normal-text AA, the calculator keeps its hue and saturation and nudges the HSL lightness in small steps until the contrast reaches 4.5:1, then shows the closest result. That keeps a brand colour recognisable while making it readable. If no lightness works against the chosen background, change the background instead.

More questions

Does dark mode need different colours for good contrast?

Usually, yes. A brand blue that passes 4.5:1 on white often fails on a near-black background, because contrast depends on both colours. Check each text colour against each background it will appear on, in both themes. Pure white text on pure black (21:1) can feel harsh for long reading, so many dark themes use an off-white on a dark grey, which still passes AAA comfortably.

Can colour alone be used to show an error or a required field?

No. WCAG Success Criterion 1.4.1 says colour must not be the only way information is conveyed, because about 1 in 12 men and 1 in 200 women have some form of colour vision deficiency. Pair a red border with an icon or text such as 'Required' or 'Error: enter a valid email'. Contrast between the red and its surroundings still needs to meet 3:1 for the border to count as a visible component.

Why do the same HEX colours look different on different screens?

HEX and RGB values are instructions, not measurements of light. A screen's brightness, colour temperature, panel type and calibration all change how a value appears, and wide-gamut displays may stretch sRGB colours unless the browser colour-manages them. The contrast ratio is calculated from the sRGB definition, so it stays the same even though the perceived colours shift slightly between devices.

What is APCA and will it replace the WCAG contrast ratio?

APCA (the Accessible Perceptual Contrast Algorithm) is a newer method being developed for the future WCAG 3. It accounts for font size and weight and for the fact that light text on dark backgrounds behaves differently from dark on light. It is still a draft and is not part of any published standard, so WCAG 2.2's contrast ratio remains the measure used for conformance and in accessibility laws.

Which web-safe or named colours pass contrast on white?

Among the CSS named colours, black, navy, maroon, purple, green, teal and darkred all pass 4.5:1 on white, while gray (#808080, 3.95:1), red (#ff0000, 4.0:1) and orange fail for normal text. The lightest neutral grey that passes AA on white is #767676 at 4.54:1. Type any of them into the calculator to see the exact ratio and the levels it meets.

Sources

This article explains how the calculator works and is general information, not financial, tax, legal or medical advice. Rules change; check the sources above or a qualified professional before you act.

Spotted a wrong result or a bug? Report a problem

May we count your visits with Invoker Analytics? It keeps a random visitor number in your browser. Your calculator inputs are never sent. Privacy policy