Developer tool · hex, rgb(), hsl() or colour names → WCAG ratio

Colour Contrast Checker (WCAG)

Enter a text colour and a background colour to get their WCAG 2 contrast ratio and a pass or fail for normal text, large text and interface parts. If a pair falls short, the checker finds the closest lighter or darker shade of the same hue that passes. Paste up to 12 brand colours to grade every combination at once. The arithmetic runs in this page, and this tool does not save what you type in local storage or session storage.

Colours

#777777 · rgb(119 119 119) · hsl(0 0% 47%)

#ffffff · rgb(255 255 255) · hsl(0 0% 100%)

Accepts #rgb, #rrggbb and #rrggbbaa, rgb() and rgba(), hsl() and hsla() in comma or space syntax, and CSS names such as rebeccapurple. A see-through text colour is blended with the background before measuring; a see-through background is placed on white first.

Result

4.48:1

4.4781 before rounding. A ratio is never rounded up onto a threshold it misses, so 4.499 shows as 4.49 and fails 4.5.

WCAG contrast results
UseLevelNeedsResult
Normal textAA4.5:1Fail
Normal textAAA7:1Fail
Large textAA3:1Pass
Large textAAA4.5:1Fail
User-interface components and graphicsAA3:1Pass

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

Large text at 24 px (18 pt)

Large bold text at 18.7 px (14 pt bold)

Input borderIcon and border: 3:1 needed

Nearest passing colours

Each suggestion keeps the hue and saturation and moves only HSL lightness, to the closest value that passes. Suggestions are solid colours.

Text colour for AA (4.5:1)

Sample text

#767676

4.54:1 at lightness 46.4%.

Text colour for AAA (7:1)

Sample text

#595959

7.00:1 at lightness 35%.

Background for AA (4.5:1)

Sample text

#060606

4.52:1 at lightness 2.5%. This flips which colour is the darker one.

Background for AAA (7:1)

No lightness of this hue reaches 7:1 against #777777. The best is #000000 at 4.69:1, so change the other colour too.

Palette matrix

Rows are the text colour, columns the background. Pick a cell to check that pair above.

A block of CSS custom properties pastes as it is: --brand: #2563eb; works, and selector and brace lines are skipped.

Contrast ratio of every palette pair, text colour by row and background by column
Text ↓ / background →InkSlateBrandSkyAmberPaper
Ink—
Slate—
Brand—
Sky—
Amber—
Paper—

AAA means 7:1 or more, AA 4.5:1, and AA large 3:1, which is enough only for large text and for interface parts such as borders and icons.

Colour Contrast Checker (WCAG)

Operator: Abdulla Al Fahad. How tools are built and checked

Grey text that looks perfectly readable on a bright office monitor can wash out on a phone in sunlight or for someone with low vision. The Web Content Accessibility Guidelines (WCAG) turn "is this readable?" into a number: the contrast ratio between the text colour and the colour behind it, from 1:1 for identical colours to 21:1 for black on white. This checker works that number out for any two CSS colours and tells you which WCAG thresholds the pair meets.

It also answers the next question a designer or developer usually has: if the pair fails, what is the closest colour that passes? For the text colour and for the background, at AA and at AAA, it keeps the hue and finds the nearest lighter or darker shade that reaches the threshold. A palette grid of up to 12 colours shows at a glance which of your brand colours can safely sit on which.

Key features

  • Contrast ratio by the WCAG 2 relative luminance formula
  • Pass or fail for normal text (AA 4.5:1, AAA 7:1), large text (AA 3:1, AAA 4.5:1) and interface components (3:1)
  • Hex, rgb(), rgba(), hsl(), hsla() and CSS colour names, with a colour picker beside each field
  • Transparent text colours blended with the background before measuring, with the blended value shown
  • Live samples of 16 px text, 24 px text, 14 pt bold text, an input border and an icon in the chosen colours
  • Nearest passing text colour and background, for AA and AAA, found by changing lightness only
  • Palette matrix of up to 12 colours, each cell showing the ratio and the best level reached
  • Copy buttons for the results as text and for the matrix as tab-separated values

How colours are read and the ratio rounded

Colours can be typed in the forms used in stylesheets: hex with 3, 4, 6 or 8 digits (with or without the #), rgb() and rgba() with numbers or percentages, hsl() and hsla() with the hue in degrees, radians, gradians or turns, and the 148 CSS colour names from aliceblue to yellowgreen, plus transparent. Both the comma form, rgb(29, 78, 216), and the space form, rgb(29 78 216 / 50%), are read. Newer forms such as oklch() and color() are refused with a message, as are var() references and currentColor, which only have a value inside a stylesheet.

Every channel is rounded to a whole 8-bit value, as a screen shows it. When the text colour has transparency it is blended with the background first, and the blend is what gets measured; the page says so and shows the blended hex. A background with transparency is first placed on white, because the checker cannot know what is behind it.

The ratio is shown to two decimals. It is rounded to the nearest hundredth, with one exception: it is never rounded up onto a threshold it does not reach. A pair at 4.499:1 shows 4.49 and fails the 4.5 requirement, instead of showing a misleading 4.50.

The palette box takes one colour per line, optionally after a name and a colon (Brand: #2563eb). Trailing semicolons and commas are ignored and lines ending in { or holding only } are skipped, so a :root block of CSS custom properties can be pasted unchanged. A .txt file up to 256 KB can be loaded into the same box.

How it works

Each colour's red, green and blue values are divided by 255 and converted from the gamma-encoded form a screen uses to linear light: values up to 0.04045 are divided by 12.92, larger ones are raised through ((c + 0.055) / 1.055) to the power 2.4. Relative luminance is then 0.2126 × red + 0.7152 × green + 0.0722 × blue, weights that reflect how much more sensitive the eye is to green than to blue.

The contrast ratio is (lighter luminance + 0.05) divided by (darker luminance + 0.05). The 0.05 stands for the glare a real screen adds even to pure black. For #777777 on white, each channel is 119/255 = 0.4667, which becomes 0.1845 in linear light, so the ratio is 1.05 / 0.2345 = 4.478. The page shows 4.48, and the pair fails AA for normal text.

For a suggestion, the colour being changed is converted to hue, saturation and lightness (HSL). The checker tries every lightness from 0% to 100% in steps of 0.1%, keeping hue and saturation, rounds each candidate to 8-bit values, and measures it against the other colour. Of the candidates that pass, it picks the one whose lightness is closest to the original. If none passes, it reports the best ratio that hue can reach, which usually means the other colour has to change as well.

Ratios, grades and suggestions are worked out by the script on this page from whatever is in the two colour fields and the palette box at that moment. Those values stay in the page's memory: the checker has no server step, saves nothing to IndexedDB, localStorage or sessionStorage, and writes to the clipboard only in response to a copy button.

When to run it

  • Checking that grey helper text and placeholder text on a form still reach 4.5:1
  • Choosing a darker shade of a brand colour for links and body text while keeping the original for large headings
  • Testing white button labels on every colour in a design system before handing it to developers
  • Grading a whole brand palette so a style guide can list which pairs are allowed for text
  • Confirming that input borders, focus rings and icons reach 3:1 against the page background
  • Checking a semi-transparent text colour, such as black at 60% opacity, as it actually appears

Running a check

  1. Type or pick the text colour in the first field and the background in the second. Swap reverses them, which is handy for checking white text on a coloured button.
  2. Read the ratio and the table of results. Normal text needs 4.5:1 for AA; large text and interface parts such as input borders and icons need 3:1.
  3. Look at the samples. They show the pair at the sizes WCAG distinguishes, so you can see the difference between normal and large text in your colours.
  4. If the pair fails, look under Nearest passing colours and press Use this colour on the option that fits your design.
  5. Paste your palette into the matrix box to check every combination, and press a cell to load that pair into the fields above.
  6. Copy the results or the matrix into a ticket, a design review or your style guide.

Example

Amber #f59e0b as text on white #ffffff

Text: #f59e0b
Background: #ffffff

Results and suggestions

Contrast ratio: 2.15:1
Normal text AA (4.5:1)   fail
Normal text AAA (7:1)    fail
Large text AA (3:1)      fail
Large text AAA (4.5:1)   fail
Interface parts (3:1)    fail

Text colour for AA:   #a56a07  4.50:1 at lightness 33.7%
Text colour for AAA:  #7b4f05  7.09:1 at lightness 25.2%
Background for AA:    #444444  4.54:1 (flips which colour is darker)
Background for AAA:   #262626  7.05:1 (flips which colour is darker)

White has no hue, so the background suggestions are greys.

For comparison, #2563eb on white is 5.17:1:
AA for normal text passes, AAA (7:1) does not.

Tips for best results

  • Check hover, focus, visited and disabled-looking states as separate pairs; a link that passes in its normal state can fail when it changes colour.
  • Dark mode is a separate set of pairs. A colour that works as text on white rarely works unchanged on a near-black background.
  • For text over a photo or gradient, check the text colour against the lightest (or darkest) part of the image behind it, or put a solid or semi-opaque panel behind the text.
  • If the lightness suggestion looks too far from the brand, try the suggestion for the other colour instead: darkening a background slightly can be less noticeable than darkening the text.
  • Thin or very small fonts look fainter than their colour suggests. The ratio does not account for font weight, so treat a pair that barely passes with a light typeface as a borderline case.
  • Paste the custom properties block from your stylesheet into the matrix box to grade the real tokens instead of retyping them.

Limits

Large text in WCAG means at least 18 point (about 24 px) or 14 point bold (about 18.7 px). Body copy at 16 px is normal text even when it looks big, so it needs 4.5:1.

The 3:1 for interface components applies to the parts needed to see and use the control, such as a text field's border or a checkbox's outline, measured against whatever is next to them. It does not lower the requirement for the text inside the control.

CSS opacity on a whole element fades its text the same way an rgba() colour does. Measure the blended colour, not the colour written in the stylesheet.

A background colour with transparency is measured as if it sat on white. If your page is dark, blend it with the real page colour first or enter the solid colour you see.

Passing the ratio does not make text accessible on its own: colour should not be the only way information is shown, and focus indicators, link underlines and error messages have their own WCAG requirements.

HSL lightness is not how bright a colour looks. Yellows and greens at 50% lightness look much lighter than blues, so the lightness change a suggestion needs can vary a lot between hues.

Common errors and how to fix them

"#12345 has 5 hex digits; a hex colour needs 3, 4, 6 or 8."
A digit was lost while copying. Copy the value again from the design file or stylesheet; most colours are six digits, such as #123456.
"var(--brand) depends on where it is used in a stylesheet."
Custom properties, currentColor and inherit have no value on their own. Look up the colour the variable is set to (in the :root block or with the browser's developer tools) and paste that.
"oklch() is not read by this checker."
Use the browser's developer tools to show the computed colour in rgb() or hex form, or convert it in a design tool, then paste that value.
"No lightness of this hue reaches 7:1 against the other colour."
With a mid-tone on one side, even black or white on the other side may fall short of 7:1. Change the other colour as well, for example darken the background suggestion and lighten the text, or settle for AA where your requirements allow it.
A palette line shows "is not a colour this checker can read".
Check that the line holds one colour, optionally after a name and a colon. Lines with two colours or with gradient syntax need to be split or simplified.

Best practices

  • Aim for 4.5:1 for all text you control, even large headings, so later font-size changes do not break compliance.
  • Record the approved text and background pairs in your design system rather than approving colours one by one.
  • Recheck the pairs whenever brand colours, themes or the page background change.
  • Combine the numbers with a quick look on a phone outdoors and with the screen brightness turned down.

Which threshold applies to what

Success criterion 1.4.3 (Contrast, Minimum) is the AA requirement most policies refer to: 4.5:1 for normal text and 3:1 for large text. Criterion 1.4.6 (Contrast, Enhanced) is the stricter AAA level: 7:1 and 4.5:1. Criterion 1.4.11 (Non-text Contrast) asks for 3:1 for the visual parts of interface components and for graphics needed to understand the content, such as the lines of a chart.

WCAG also lists exceptions: text that is purely decorative, text in logos and brand names, and inactive (disabled) controls have no contrast requirement. These numbers are the same in WCAG 2.1 and 2.2, and this checker uses the WCAG 2 formula they are measured against. A draft for a future version of WCAG uses a different method, so a ratio from this page should not be compared with scores from that method.

Reading the palette matrix

Each row is a colour used as text and each column a colour used as the background, so the cell in the Ink row and Paper column is Ink text on Paper. For solid colours the grid is symmetric, because swapping two solid colours gives the same ratio. With a transparent colour in the palette the two halves differ, since the transparent colour is blended with whatever it sits on.

Each cell gives the ratio and the highest text level it reaches: AAA from 7:1, AA from 4.5:1, AA large from 3:1, and Fail below that. AA large is also the level needed for borders and icons. Pressing a cell copies the pair into the main fields, where the suggestions can find a passing shade for it.

Gradients, photos and colour spaces it leaves out

It measures pairs of flat colours. It does not sample colours from a screenshot, read a web page, follow CSS variables or simulate colour vision deficiencies, and it does not handle gradients or text over images. Suggestions change only HSL lightness; if you need to keep lightness and change saturation instead, adjust the colour yourself and check it again. The palette grid holds up to 12 colours, or 132 pairs.

Frequently asked questions

Why does #777777 on white fail when it looks fine to me?

Its ratio is 4.478:1, just under the 4.5:1 needed for normal text at AA. The requirement is set for people with moderately low vision and for poor viewing conditions, not for a good monitor in a dim office. One step darker, #767676, reaches 4.54:1 and passes.

Why do some other checkers show a slightly different number?

Checkers differ in rounding and in how they treat transparency. This one rounds each colour to 8-bit values, blends transparent colours as a browser does, and never rounds a ratio up onto a threshold. The pass or fail result is decided from the unrounded ratio.

Does text size change the ratio?

No. The ratio depends only on the two colours. Size decides which threshold applies: large text, at 24 px regular or about 18.7 px bold and above, needs 3:1 for AA instead of 4.5:1.

Does the order of the two colours matter?

Not for solid colours: the lighter one always goes on top of the fraction. It matters when the text colour is partly transparent, because it is blended with the background before measuring.

Can I check a colour against both light and dark themes?

Check each pair separately: once with the light background and once with the dark one. Or put the text colour and both backgrounds in the palette box and read both cells in its row.

Why are the background suggestions grey when my background is white?

White, black and every grey have no hue and zero saturation, so changing only their lightness can produce nothing but other greys. With amber text on white, the closest backgrounds that pass are #444444 for AA and #262626 for AAA, both darker than the text. If you want a tinted background, type one in, such as a pale amber; the suggestions then keep that tint while changing its lightness.