Audit Color Contrast Against WCAG with AI
Reads a list of foreground/background color pairs and returns contrast ratios, WCAG 1.4.3 (text) and 1.4.11 (non-text) pass/fail per pair, the contrast level achieved (AA / AAA), and closest WCAG-passing alternative per failing pair.
When to use it
- Reviewing a brand palette before product use.
- Auditing an existing UI for contrast violations.
- Designing a dark mode color set.
- Documenting contrast decisions in a design system.
The prompt
<role>You are a design systems engineer with deep accessibility background. You compute contrast ratios precisely (or describe the formula) and you don't conflate text contrast with non-text contrast.</role> <context>WCAG contrast rules:- **SC 1.4.3 (Contrast Minimum, AA)**: text vs background: - Normal text: contrast ratio >= 4.5:1 - Large text (>= 18pt regular OR 14pt bold): >= 3:1- **SC 1.4.6 (Contrast Enhanced, AAA)**: text: - Normal: >= 7:1 - Large: >= 4.5:1- **SC 1.4.11 (Non-Text Contrast, AA)**: UI components (form input borders, icon outlines, focus rings, custom check states): >= 3:1 Contrast formula: (L1 + 0.05) / (L2 + 0.05), where L1 is luminance of lighter color, L2 of darker. Luminance computed from sRGB → linearized RGB → weighted sum.</context> <task>For the color pairs below:1. Compute the contrast ratio per pair (or describe how: exact ratios optional).2. Determine WCAG pass/fail per usage: - Text usage: pass at 4.5:1 (normal) or 3:1 (large), AAA at 7:1 (normal) or 4.5:1 (large) - Non-text (UI elements): pass at 3:13. For each failing pair, suggest a closest-WCAG-passing alternative (adjust foreground OR background, keep brand intent).4. Note any pair that's borderline (within 0.1 of the threshold).</task> <input>Color pairs (foreground / background, hex or CSS): {pairs}Usage context per pair (text / large text / non-text UI): {usage}Brand color constraints (which colors are locked): {constraints}</input> <constraints>- Cite SC number per pass/fail decision.- Compute every ratio with the WCAG relative-luminance formula and show 2 decimals; never estimate from how similar the colors look. Re-check each suggested alternative the same way.- "Large text" definition explicit: >= 18pt (24px) regular OR >= 14pt (18.66px) bold. 18px regular is NOT large.- Non-text (UI) uses 3:1, not 4.5:1: don't conflate.- Alternatives respect brand-locked colors; only adjust the non-locked side.- Borderline cases (within 0.1) flagged as risky.</constraints> <output_format>Markdown table: Pair | FG | BG | Usage | Ratio | WCAG (SC + AA/AAA) | Status | Suggested alternative. Followed by a "Summary" paragraph (X of Y pairs pass) and a "Brand-color implications" paragraph if alternatives shift the palette.</output_format> <approach>Before writing, identify which pairs are TEXT vs UI element: the threshold differs.</approach>## RoleDesign systems engineer. Accessible contrast. Precise computation. Distinguish text vs non-text. ## ContextWCAG contrast:- SC 1.4.3 (AA) text: normal >= 4.5:1, large (>= 18pt OR 14pt bold) >= 3:1- SC 1.4.6 (AAA) text: normal >= 7:1, large >= 4.5:1- SC 1.4.11 (AA) non-text (UI): >= 3:1 Contrast formula: (L1 + 0.05) / (L2 + 0.05). ## TaskFor color pairs:1. Compute ratio per pair.2. Determine WCAG pass/fail by usage (text vs large vs non-text).3. For failing pairs, suggest closest-passing alternative (respect brand-locked colors).4. Note borderline (within 0.1 of threshold). ## Input- Pairs: {pairs}- Usage per pair: {usage}- Brand constraints (locked colors): {constraints} ## Constraints- Cite SC number per decision.- Compute ratios with the WCAG relative-luminance formula, 2 decimals; re-check every alternative.- Large text: >= 18pt (24px) regular OR >= 14pt (18.66px) bold. 18px regular is not large.- Non-text = 3:1, not 4.5:1.- Alternatives respect locked colors.- Borderline (within 0.1) flagged. ## Output formatMarkdown table: Pair | FG | BG | Usage | Ratio | WCAG (SC + AA/AAA) | Status | Alternative. Followed by Summary + Brand-color implications paragraphs. ## ApproachIdentify TEXT vs UI element first: threshold differs.Example
Input
Color pairs: 1. #FFFFFF foreground on #2563EB background: primary button label 2. #6B7280 foreground on #FFFFFF background: body text 3. #2563EB foreground on #FFFFFF background: link text in body 4. #94A3B8 foreground on #FFFFFF background: placeholder text in inputs 5. #1F2937 foreground on #FFFFFF background: body heading text 6. #D1D5DB on #FFFFFF: form input border (UI element) 7. #2563EB on #FFFFFF: focus ring on buttons (UI element) 8. #16A34A on #FFFFFF: success badge text (small, regular weight) Usage: 1. text (normal weight, 14px button label) 2. text (normal weight, 14px body) 3. text (normal weight, 14px inline link) 4. text (normal weight, 14px placeholder) 5. text (normal weight, 18px heading, regular weight) 6. non-text UI (form input border) 7. non-text UI (focus ring) 8. text (normal weight, 12px badge) Brand constraints: #2563EB is locked (primary brand color); cannot change.
Output
## Contrast audit Ratios computed with the WCAG 2.x relative-luminance formula, rounded to 2 decimals. | # | FG | BG | Usage | Ratio | WCAG | Status | Alternative | |---|----|----|-------|-------|------|--------|-------------| | 1 | #FFFFFF | #2563EB | Text (normal, 14px) | 5.17:1 | SC 1.4.3 AA | ✅ PASS (AA; AAA needs 7:1) | - (brand color locked) | | 2 | #6B7280 | #FFFFFF | Text (normal, 14px) | 4.83:1 | SC 1.4.3 AA | ✅ PASS (AA) | #4B5563 (7.56:1) if you want AAA | | 3 | #2563EB | #FFFFFF | Text (inline link) | 5.17:1 | SC 1.4.3 AA | ✅ PASS (AA) | - (brand color locked) | | 4 | #94A3B8 | #FFFFFF | Text (placeholder) | 2.56:1 | SC 1.4.3 AA | ❌ FAIL (needs 4.5:1) | #64748B (4.76:1), same slate family | | 5 | #1F2937 | #FFFFFF | Text (18px regular: NOT large text, which starts at 24px regular / 18.66px bold) | 14.68:1 | SC 1.4.3 AA + 1.4.6 AAA | ✅ PASS (AAA) | - | | 6 | #D1D5DB | #FFFFFF | Non-text UI (input border) | 1.47:1 | SC 1.4.11 AA | ❌ FAIL (needs 3:1) | #9CA3AF is still only 2.54:1; #6B7280 (4.83:1) passes | | 7 | #2563EB | #FFFFFF | Non-text UI (focus ring) | 5.17:1 | SC 1.4.11 AA | ✅ PASS | - | | 8 | #16A34A | #FFFFFF | Text (small badge, 12px) | 3.30:1 | SC 1.4.3 AA | ❌ FAIL (needs 4.5:1) | #15803D (5.02:1), or a #DCFCE7 fill with #166534 text (6.49:1) | ## Summary **5 of 8 pairs pass**. Three failures: - **Placeholder text (#94A3B8)**: common issue; placeholder text often fails. Use #64748B for the placeholder AND keep a visible label so nothing depends on placeholder text. - **Form input border (#D1D5DB)**: extremely common; design systems use light gray for "subtle" borders that fail non-text contrast. One step darker (#9CA3AF) is not enough: go to #6B7280, or keep the light border and add a 3:1 cue such as a darker bottom border. - **Success badge text (#16A34A on #FFFFFF)**: 12px green text is a notorious failure mode. Darken to #15803D OR use a background fill (#DCFCE7) with #166534 text. ## Brand-color implications The primary brand color (#2563EB) is locked. Every pair that uses it passes AA (5.17:1 against white), but it can never reach AAA for text on white, so do not promise AAA anywhere the brand blue carries text. The failures are around grays (borders, placeholders) and the secondary green (#16A34A). Recommend: 1. **Darken the grays that carry meaning**: #94A3B8 → #64748B for placeholders, #D1D5DB → #6B7280 for input borders. Loses subtlety, gains accessibility. 2. **Define a separate "accessible green"** (#15803D or darker) for text uses of the brand green. Keep #16A34A for backgrounds and decorative use only. 3. **Document the constraint in the design system**: "Text colors below 4.5:1 and UI colors below 3:1 against their background MUST go through accessibility review." This prevents drift.
Common pitfalls
- Model computes ratios incorrectly: high tolerance for hex codes that are visually similar. Use a tool to verify if precision matters.
- Non-text contrast (3:1) conflated with text (4.5:1): they're different thresholds.
- Brand-locked colors ignored; alternatives suggest changing the brand color.
- Borderline cases (within 0.1 of threshold) marked PASS without note: they're at risk after any future palette shift.
Tips
- Use a contrast tool (axe, WebAIM Contrast Checker, Chrome DevTools) to verify computed ratios before publishing.
- Document accessible alternatives in the design system, not just per-component fixes.
- Pair with `wcag-2-2-aa-suite` for the rest of the visual accessibility surface.
- Re-audit when designers change neutrals or add new brand colors.
FAQ
What's the difference between AA and AAA contrast?
AA is the legal baseline (4.5:1 for normal text). AAA is the enhanced standard (7:1). Most teams target AA; AAA is reserved for products serving users with low vision specifically. Don't pursue AAA at the expense of brand consistency unless your audience needs it.
How do I handle the 'large text' exception?
Large text is defined as >= 18pt regular OR >= 14pt bold. In CSS, roughly 24px regular OR 18.66px bold. Most body text doesn't qualify. Use the relaxed threshold (3:1) only when the text definitively meets the size criteria.
Are placeholder colors a real accessibility issue?
Yes. Placeholder text often fails contrast AND disappears on focus, leaving users without context. Best practice: don't rely on placeholder as a label substitute. Have a visible `<label>` element AND a placeholder for hints.
What about brand colors that can't pass?
Use them for non-text purposes (backgrounds, icons, decorative). Pair with WCAG-passing colors for text. Document which colors are 'text-safe' vs 'decoration-only' in the design system.