Toolvito

Works on this device

Color Contrast Checker

Type a text colour and a background colour. The tool works out the WCAG contrast ratio and tells you in words if the pair passes level AA and level AAA. It can also find the nearest lighter or darker colour that passes.

Enter your values

The WCAG contrast ratio of two colours, with pass or fail for levels AA and AAA.

Your values

Hex, rgb(), hsl() or a CSS colour name, such as #767676 or rgb(118, 118, 118). Opacity is read too, as in rgba(0, 0, 0, 0.6).

A solid colour, in any of the same forms.

Your values are worked out in this browser. They are not sent to a server.

Your result will show here

Fill in the values, then choose Check.

How to use this checker

  1. Type the text colour and the background colour. You can use hex such as #767676, rgb(), hsl() or a CSS colour name such as navy.
  2. Read the contrast ratio and the lines below it. Each line says passes or fails in words, for normal text, large text and user interface parts. A sample shows the words "Sample text 123" in your text colour on your background, in normal and in large size.
  3. If the pair fails, choose Find the nearest colour that passes. Pick the ratio you need and the colour that may change.
  4. For links inside a paragraph, choose Link colour against text and background.

The formula

The Web Content Accessibility Guidelines (WCAG) 2.2 define the contrast ratio as (L1 + 0.05) ÷ (L2 + 0.05). L1 is the relative luminance of the lighter colour and L2 that of the darker colour. The ratio goes from 1:1 (the same colour twice) to 21:1 (black and white).

Relative luminance is 0.2126 × R + 0.7152 × G + 0.0722 × B. Before that, each sRGB channel c from 0 to 1 is made linear: c ÷ 12.92 when c is 0.03928 or less, and ((c + 0.055) ÷ 1.055) to the power 2.4 above that.

WCAG 2 writes the limit as 0.03928 and the sRGB standard writes 0.04045. No 8-bit colour value lies between the two, so both give the same result for colours from 0 to 255.

The ratios that WCAG 2.2 asks for

Contrast ratios in WCAG 2.2
Use Level AA Level AAA
Normal text 4.5:1 (criterion 1.4.3) 7:1 (criterion 1.4.6)
Large text 3:1 (criterion 1.4.3) 4.5:1 (criterion 1.4.6)
User interface parts and graphics 3:1 (criterion 1.4.11) no separate ratio

Large text is at least 18 point (24 CSS pixels), or at least 14 point (about 18.66 CSS pixels) when it is bold. User interface parts are things such as the border of a text box, an icon that has a meaning, or the mark that shows keyboard focus.

WCAG has exceptions that this tool cannot judge for you: logos, text that is only decoration, and parts that are not active.

Worked example

Grey text #767676 on white. Each channel of the grey is 118 ÷ 255 = 0.4627. Linear value = ((0.4627 + 0.055) ÷ 1.055) to the power 2.4 = 0.1812, so the luminance of the grey is 0.1812. White has luminance 1.

Contrast ratio = (1 + 0.05) ÷ (0.1812 + 0.05) = 4.54. This passes level AA for normal text (4.5:1) and fails level AAA (7:1).

One step lighter, #777777, gives 4.47:1 and fails level AA for normal text. So #767676 is the lightest grey that passes on white.

Colours with opacity

A text colour such as rgba(0, 0, 0, 0.6) lets the background show through. The tool first works out the colour you see: each channel = text × opacity + background × (1 − opacity). Black at 60% opacity on white is seen as #666666, and that colour is checked.

The background must be solid. A background with opacity shows what lies behind it, and the tool cannot know that colour.

How the suggestion is found

The tool keeps the hue and the saturation of the colour (in the HSL model) and changes only the lightness. It goes in steps of 0.1% and tries every step in turn, darker or lighter, until the ratio is reached. The first step that passes is the nearest one in that direction.

Sometimes no version passes. For example, no text colour reaches 7:1 on the mid grey #777777: black gives 4.68:1 and white gives 4.47:1. Then the tool says so, and you need to change the other colour.

Limits you should know

  • A contrast ratio is one requirement. A page can pass it and still be hard to read or use. Font size and weight, spacing, images of text, focus marks, and much more are part of accessibility.
  • The tool checks colours that you type. It does not read a web page, a PDF or a picture, and it does not find the colours on your site.
  • Text on a picture or on a gradient has many background colours. Check the place where the contrast is lowest.
  • This is the WCAG 2 method. The draft method APCA has other rules and its own licence terms, and it is not part of this tool.
  • Laws and rules such as the ADA, Section 508, EN 301 549 or AODA point to WCAG levels. This tool gives one number for one pair of colours. It is not a legal check and not professional advice.
  • The suggestion keeps hue and saturation in the HSL model. Another colour space could give a slightly different nearest colour.

Related tools