ColorContrastLabWCAG CONTRAST

Color pair in, WCAG verdict out

Check any text and background pair against WCAG — then fix it in one click

Type a HEX, RGB or HSL value for the text and the background, or pick a color from the wheel. ColorContrastLab computes the WCAG 2.2 relative luminance and contrast ratio, shows AA and AAA results for normal text, large text and UI components, simulates five kinds of color vision, and exports the pair as CSS custom properties or Tailwind tokens. Nothing is uploaded; the math happens on this page.

Standard WCAG 2.2 SC 1.4.3, 1.4.6, 1.4.11Formula (L1 + 0.05) ÷ (L2 + 0.05)Runs 100% in this browser

Contrast checker

Samples

Text color

#1A1A1A

100%

Background color

#FFFFFF

100%

Color vision

The same pair, through five kinds of eyes

Roughly one in twelve men and one in two hundred women have a color-vision deficiency. The cards above recolor your current pair for each type and recalculate the ratio, so you can see where a passing design stops being readable.

17.40:1

Normal vision

Trichromatic

Pass · AA 4.5:1

17.40:1

Protanopia

No red (L) cone

Pass · AA 4.5:1

17.40:1

Deuteranopia

No green (M) cone

Pass · AA 4.5:1

17.40:1

Tritanopia

No blue (S) cone

Pass · AA 4.5:1

17.40:1

Achromatopsia

No color, luminance only

Pass · AA 4.5:1

Simulation uses the Machado, Oliveira & Fernandes (2009) matrices at severity 1.0, applied in linear light, and then recomputes contrast from the simulated colors. It is a design aid, not a diagnosis of anyone's vision.

Protanopia — red-blind

The L-cone is missing, so red and green collapse toward the same dark yellow-brown. Reds darken sharply; dark red text on black almost disappears. About 1% of men.

Deuteranopia — green-blind

The M-cone is missing, the most common type in men (about 1 in 20). Green text on red, and the classic red/green status pair, lose their difference.

Tritanopia — blue-blind

The S-cone is missing: blue and green merge, and yellow can look pink or gray. Rare, and not sex-linked.

Achromatopsia — no color

Only luminance remains. Contrast is exactly what this reader has left, which is why a solid ratio helps more than hue does.

Palette

Save the pairs and colors worth keeping

Save a checked pair, then collect text and background colors to compare every combination at once. Saved pairs and palette colors feed the export below.

Saved pairs

0

Each pair keeps its own text, background and opacity.

    No saved pairs yet. Check a pair above, name it if you like, and press Save.

    Palette colors

    0

    Every color you add is tested as text and as background against every other.

      No palette colors yet. Add the text or background color to build a matrix.

      Add at least two colors and every combination appears here, row by row.

      Rows are text colors, columns are backgrounds. AAA = 7:1 or more, AA = 4.5:1 or more, AA-L = large text and UI only (3:1), — = below 3:1.

      Export

      Take the tokens straight into your project

      The current pair, your saved pairs and the palette become CSS custom properties, a Tailwind config, or CSS v4 @theme tokens. Copy the text or download the file — both are generated in this tab.

      /* ColorContrastLab — CSS custom properties
         Current pair: #1A1A1A on #FFFFFF = 17.40:1
      */
      :root {
        --fg: #1A1A1A;   /* text */
        --bg: #FFFFFF;   /* background */
      }
      

      CSS custom properties

      Drop the block into any stylesheet and use var(--fg) on text, var(--bg) on the surface. Saved pairs become .pair-N classes you can put on a component.

      :root {
        --fg: #1A1A1A;
        --bg: #FFFFFF;
      }

      Tailwind config

      Extend the theme with the pair and palette so text-fg on bg-bg, or bg-palette-2, works in class names. Tailwind v3 reads this file as tailwind.config.js.

      colors: {
        fg: "#1A1A1A",
        bg: "#FFFFFF",
      }

      CSS v4 @theme

      In Tailwind CSS v4 the tokens live in CSS. Paste the @theme block into your stylesheet and Tailwind generates the utilities for you.

      @theme {
        --color-fg: #1A1A1A;
        --color-bg: #FFFFFF;
      }

      Export covers the current pair, saved pairs and palette colors only; nothing is fetched or signed. Check the printed comment above each token if you need to know what ratio it was chosen for.

      How it works

      Four steps from two colors to a checked token

      No settings to learn: the ratio updates as you type.

      01

      Set the text color

      Type HEX, RGB or HSL, use the wheel, or start from a sample. Lower the opacity to see how transparency changes the result.

      02

      Read the verdict

      The big number is the contrast ratio. Five badges check normal text, large text and UI components against the AA and AAA lines.

      03

      Auto-fix if it fails

      One click moves the text — and, only if it must, the background — to the nearest color that passes, keeping the hue and saturation.

      04

      Simulate and export

      Look at the pair through four color-vision deficiencies, then copy or download the CSS and Tailwind tokens.

      The formula

      How the contrast ratio is calculated

      ColorContrastLab uses the relative luminance definition in WCAG 2.2 (which is numerically identical to WCAG 2.1 for 8-bit colors) and composites transparency the way CSS paints it.

      Each sRGB channel is divided by 255 and linearized, because luminance is not gamma-encoded. The three linear channels are weighted 0.2126 red, 0.7152 green and 0.0722 blue — the coefficients that follow the human eye's sensitivity — and summed into the relative luminance L.

      The contrast ratio puts the lighter luminance over the darker one, adds 0.05 to both (the flare term that keeps the ratio finite for black), and divides. The result runs from 1:1 for identical colors to 21:1 for pure black on pure white.

      L = 0.2126·R + 0.7152·G + 0.0722·B R,G,B = linear sRGB
      C = c/12.92 (c ≤ 0.04045) · C = ((c+0.055)/1.055)2.4 (c > 0.04045)
      ratio = (Llight + 0.05) / (Ldark + 0.05)
      csRGB channel, 0–1 (8-bit value ÷ 255)
      Clinear channel value
      Lrelative luminance, 0–1
      L1, L2the lighter and the darker of the two luminances

      Worked example: #767676 on #FFFFFF gives L1 = 1.0000 and L2 = 0.1812, so (1.0000 + 0.05) ÷ (0.1812 + 0.05) = 4.54:1 — just past the 4.5:1 AA line, and well short of 7:1.

      Thresholds

      What WCAG 2.2 asks for

      AA is the level most policies and laws reference; AAA is stricter and usually applied to body text where it is practical.

      Text or elementMinimum ratioSuccess criterion
      Normal text under 18 pt (24 px), or under 14 pt (18.66 px) bold4.5:1AA · 1.4.3 Contrast (Minimum)
      Normal text, AAA7:1AAA · 1.4.6 Contrast (Enhanced)
      Large text: 18 pt (24 px) and up, or 14 pt (18.66 px) bold and up3:1AA · 1.4.3
      Large text, AAA4.5:1AAA · 1.4.6
      UI components: borders, icons, focus rings, form outlines3:1AA · 1.4.11 Non-text Contrast
      Logos, decorative text, disabled controlsno requirementExempt from 1.4.3 and 1.4.11

      Point sizes are CSS pt at 96 dpi: 18 pt = 24 px, 14 pt = 18.66 px. Bold means a font weight of at least 700 in most interpretations. Ratios are not rounded by WCAG, so 4.49:1 fails 4.5:1.

      Questions

      Contrast questions people actually ask

      What ratio do I need to pass WCAG?

      4.5:1 for normal text at AA, 3:1 for large text and UI components, and 7:1 or 4.5:1 respectively if you are aiming at AAA. If you only remember one number, remember 4.5:1 for body text.

      Two colors look clearly different — why do they still fail?

      Contrast is about luminance, not hue. Pure red (#FF0000) and pure green (#00FF00) are obviously different colors, yet red on white is only 4.00:1 and red on green is 1.28:1. The eyes of a reader with low vision or a color-vision deficiency have less to work with than yours.

      How does auto-fix choose the new color?

      It keeps the hue and saturation of the text color and moves lightness in 0.1% steps, both darker and lighter, and takes the nearest value that meets the target. If no text color can reach the target on that background — a mid-gray background cannot support 7:1 — it moves the background as little as possible and then picks the text color.

      Is 4.5:1 enough for an accessible page?

      It is the AA floor for text, not a guarantee. Font size, weight, spacing, state changes and the reader's own settings all matter, and AAA (7:1) is noticeably easier to read. Use 4.5:1 as the minimum and go higher for body copy where you can.

      Why does lowering the opacity change my result so much?

      A transparent color is painted over what is behind it, so the effective color is a mix. The tool composites the text over the background, and the background over white, exactly as CSS does, then measures the mix. 50% black on white is #808080, which is only 3.95:1.

      What do the color-vision cards show?

      They recolor the same pair using published protanopia, deuteranopia, tritanopia and achromatopsia matrices and recalculate the ratio from the simulated colors. A pair that passes for you can drop below 4.5:1 for a reader with deuteranopia — that is the pair you need to fix.

      Is anything sent to a server?

      No. The colors, saved pairs and exports are handled in this tab. The only network request is the Google AdSense loader in the page head; blocking it does not affect the checker. Saved pairs live in your browser's local storage until you clear them.

      Can I use the export in Tailwind v3 and v4?

      Yes. The Tailwind config tab produces a theme.extend.colors block for tailwind.config.js (v3 and the v4 compatibility layer), and the @theme tab produces CSS custom properties for Tailwind CSS v4. The CSS variables tab is framework-free.

      Limits

      What this checker does not do

      It does not read your page

      The checker measures the two colors you give it. It does not crawl your site, inspect rendered text, or know which pixels sit behind a transparent element.

      It is not an audit

      Passing AA here does not certify a page. Accessibility also needs keyboard access, semantics, labels, motion and zoom behavior, and WCAG 2.2 adds focus appearance and target size.

      Simulation is a model

      The matrices approximate one severity of each deficiency. Real color vision varies, and monitor calibration changes the colors you see while checking.

      Hover and state colors are yours to check

      Links, visited links, placeholder text and disabled states each need their own pair. Check them one by one.

      Gradients and images

      Over a gradient or a photo the ratio changes pixel by pixel. Sample the lightest and darkest points, or put a solid scrim behind the text.

      No history

      Saved pairs stay in this browser only. Clearing site data removes them, and they are not synced between devices.

      References

      • WCAG 2.2 — W3C Recommendation, 5 October 2023 — SC 1.4.3, 1.4.6, 1.4.11 and the relative luminance definition.
      • WCAG 2.1 — W3C Recommendation, 5 June 2018 — same luminance formula for 8-bit colors.
      • Machado et al. 2009 — A Physiologically-based Model for Simulation of Color Vision Deficiency, IEEE TVCG 15(6).
      • sRGB — IEC 61966-2-1 — the transfer function used for linearisation.
      • CSS Color 4 — Alpha compositing order and the rgb() / hsl() syntax the fields accept.