# WCAG Contrast Checker

> Check the contrast ratio of text and background against WCAG 2.2 AA and AAA, with a suggested fix. Works with hex, rgb, hsl, oklch and transparency.

- Page: https://notadevblog.com/en/tools/color/contrast-checker/
- German version: https://notadevblog.com/de/tools/color/contrast-checker.md
- Category: Color

## At a glance

- **Processing:** Locally in your browser, also offline once the page has been opened. Input never leaves your device.
- **Standard:** WCAG 2.2 contrast ratio; the APCA value is shown as a draft for WCAG 3
- **Colors:** Hex, rgb, hsl, oklch, Display-P3 and names; transparency is composited, colors outside sRGB are clamped and flagged

## For agents

WebMCP: the page registers these functions via document.modelContext in browsers that support it.
ES module: https://notadevblog.com/core/contrast-checker.js
Every function returns { "ok": true, ... } or { "ok": false, "error": { "code", "message" } }.

### contrast_check

Contrast ratio of two colors per WCAG 2.2 ((L1+0.05)/(L2+0.05)) with AA and AAA verdicts. Colors: hex, rgb(), hsl(), oklch(), oklab(), color(srgb|display-p3 ...), CSS names; alpha allowed. A translucent foreground is composited over the background, a translucent background over white (both reported in notes). Colors outside sRGB are clamped and flagged. ratio is rounded to 2 decimals, but a value below a threshold (3, 4.5, 7) never shows as reaching it: 4.499 shows 4.49 and fails 4.5. Verdicts use the unrounded value. wcag holds the thresholds: AA normal 4.5, AA large 3, AA ui (components, graphics) 3, AAA normal 7, AAA large 4.5. Give fontSizePx (and fontWeight) to also get text.large (>= 24 px, or >= 18.66 px at weight >= 700) and the verdict for that size. If AA fails for the text size (4.5 without fontSizePx), suggestion is the foreground closest in OKLCH lightness (same hue and chroma) that passes. apca.lc is the APCA-W3 Lc value (WCAG 3 draft, not a conformance criterion; positive = dark text on light).

Parameters:
- foreground (string, required): Text or icon color. Hex without # works in links.
- background (string, required)
- fontSizePx (number)
- fontWeight (integer, 1..1000)

Example input: `{"foreground":"#777777","background":"#ffffff","fontSizePx":16}`

Deep link (options in the query, user data after #): https://notadevblog.com/en/tools/color/contrast-checker/?foreground=%23777777&background=%23ffffff&fontSizePx=16

## How to use

1. **Enter two colors:** Type or pick the text color and the background color. Any CSS color works, for example #1a1a1a, oklch(0.6 0.15 250) or rebeccapurple.
2. **Set the text size:** Enter font size and weight. Large text needs a lower ratio, so the verdict depends on size.
3. **Read the verdict:** See the ratio, which levels pass and, if AA fails, the closest foreground color that passes.

## About this tool

Low contrast is one of the most common accessibility failures. WCAG measures it as the ratio of the relative luminance of two colors, from 1:1 (identical) to 21:1 (black on white).

The suggestion keeps hue and chroma and changes only the lightness in OKLCH, so the fixed color still looks like yours.

## Frequently asked questions

### What contrast ratio does WCAG require?

AA needs 4.5:1 for normal text and 3:1 for large text and interface components. AAA needs 7:1 for normal and 4.5:1 for large text.

### What counts as large text?

Text of at least 24 px (18 pt), or at least 18.66 px (14 pt) in bold. Everything smaller is normal text.

### Why does 4.499:1 not pass 4.5:1?

WCAG gives no rounding. The verdict uses the exact value, and the display never shows a failing value as reaching the threshold.

### How are transparent colors handled?

A translucent text color is blended over the background. A translucent background is assumed to sit on white, and the tool says so.

### What is the APCA value?

APCA is the contrast method proposed for WCAG 3. Its Lc value is shown for information only; WCAG 2.2 conformance is decided by the ratio.
