DEV Community

Ajit Vishwakarma
Ajit Vishwakarma

Posted on Originally published at bramhify.com

WCAG 2.2 AA & AAA Color Contrast Cheat Sheet for Devs

Nothing fails a Lighthouse accessibility audit—or frustrates real users squinting at their phone in daylight—faster than sleek, low-contrast grey text (#9ca3af) sitting on a white or translucent glassmorphic card. Beyond user experience, WCAG 2.2 Level AA contrast compliance is now a legal requirement across the EU European Accessibility Act (EAA), US ADA / Section 508, and enterprise SaaS procurement checklists.

Bramhify's 100% offline Color Contrast Checker computes the exact W3C relative luminance contrast ratio (1:1 to 21:1) in real time as you type hex codes or tweak color pickers—instantly showing WCAG AA and WCAG AAA Pass/Fail badges for both Normal and Large text plus a 1-click Foreground/Background swap button.

WCAG 2.2 Contrast Ratio Requirements Cheat Sheet

Element Type Font Size Threshold WCAG AA (Standard Target) WCAG AAA (Enhanced) Examples
Normal Body Text < 18pt (24px) regular OR < 14pt (18.66px) bold 4.5 : 1 7.0 : 1 Paragraphs, nav links, table cells, form labels, button copy
Large Text >= 18pt (24px) regular OR >= 14pt (18.66px) bold 3.0 : 1 4.5 : 1 Hero headlines (H1/H2), stat counters, section titles
Non-Text UI Components & Icons WCAG 2.1 / 2.2 SC 1.4.11 3.0 : 1 — Input borders, focus rings, toggle switches, chart bars, standalone icons
Disabled Controls & Pure Logos Exempt per W3C spec Exempt Exempt Inactive disabled buttons, brand wordmarks

Watch Out for the pt vs px Trap: In CSS, 1pt = 1.333px. That means WCAG's "14pt bold" large-text threshold is 18.67px (~19px) bold, NOT 14px bold! A 14px bold button label still requires the full 4.5:1 normal-text ratio!

Test Foreground & Background Contrast Offline:

Bramhify Color Contrast Checker showing live preview, exact contrast ratio, and WCAG AA/AAA Pass/Fail badges
Real-time W3C relative luminance calculation with live text preview, 1-click color swap, and AA/AAA badges—100% locally.

Try the 100% browser-local tool: Color Contrast Checker on Bramhify — zero uploads, zero tracking, runs entirely in your browser.

Battle-Tested Accessible Color Pairs (Copy-Paste Design Tokens)

Stop guessing which Tailwind/indigo/emerald shades actually pass 4.5:1 on both Light and Dark themes:

Light Mode Safe Tokens (Background #FFFFFF or #F8FAFC)

  • Primary Body Text: #0F172A on #FFFFFF → 17.8 : 1 (AAA)
  • Muted / Secondary Metadata: #475569 on #FFFFFF → 7.5 : 1 (AAA) (Avoid #94A3B8—it fails at 2.56:1!)
  • Primary Brand Button: #FFFFFF on #2563EB → 5.17 : 1 (AA) or #FFFFFF on #4F46E5 → 6.29 : 1 (AA)
  • Success / Error Text: #047857 (5.48:1) and #B91C1C (6.47:1) on #FFFFFF

Dark Mode Safe Tokens (Background #0F172A or #111827)

  • Primary Body Text: #F8FAFC on #0F172A → 17.1 : 1 (AAA) (Slightly softer than pure #FFF on #000 to reduce halation for astigmatic eyes!)
  • Muted / Secondary Metadata: #94A3B8 on #0F172A → 6.9 : 1 (AA+)
  • Interactive Links & Accents: #60A5FA (6.8:1) or #818CF8 (5.6:1) on #0F172A (Never reuse dark #2563EB link blue on #0F172A—it drops to a failing 3.4:1!)

4 Subtle Contrast Mistakes Even Senior Frontend Devs Miss

  1. Placeholder Text Inside Inputs: Default browser placeholder grey frequently sits around 2.4:1. Explicitly style ::placeholder to at least #64748B (light mode) or #94A3B8 (dark mode) so form hints stay readable.
  2. Focus Outlines (:focus-visible): WCAG 2.2 SC 2.4.11 & 1.4.11 require keyboard focus indicators to achieve at least 3.0:1 against adjacent backgrounds—never write outline: none without a high-contrast replacement ring!
  3. White Text on Vibrant Green / Orange / Yellow Buttons: #FFFFFF on #22C55E (bright green) or #F59E0B (amber) looks cheerful to sighted designers yet fails badly (2.28:1 and 2.15:1)! Either darken the button background (#15803D, #B45309) or switch the label text to dark slate (#0F172A).
  4. Hover & Active States: A link that passes at rest (4.8:1) can silently drop below 4.5:1 on :hover if you lighten it on white or darken it on dark slate. Always test hover states too!

How the W3C Contrast Formula Works

WCAG converts each sRGB channel (R, G, B scaled 0–1) into linearized relative luminance (L):

function relativeLuminance(r, g, b) {
  const [R, G, B] = [r, g, b].map(v => {
    const s = v / 255;
    return s <= 0.03928 ? s / 12.92 : ((s + 0.055) / 1.055) ** 2.4;
  });
  return 0.2126 * R + 0.7152 * G + 0.0722 * B;
}
// Ratio = (L_lighter + 0.05) / (L_darker + 0.05)
Enter fullscreen mode Exit fullscreen mode

Notice that human eyes perceive green (0.7152) as roughly 10× brighter than blue (0.0722)—which explains why pure white text passes easily on royal blue #2563EB yet fails on bright green #22C55E!

Frequently Asked Questions (FAQs)

Is WCAG AA (4.5:1) or WCAG AAA (7.0:1) required for most websites?

WCAG 2.2 Level AA (4.5:1 normal text, 3.0:1 large text and UI borders) is the global legal and industry compliance standard for SaaS apps, e-commerce stores, and public websites. Level AAA (7.0:1) is an aspirational enhancement recommended for long-form reading, healthcare, and government portals.

What counts as "Large Text" under WCAG 2.2?

Large text is defined as 18pt (24px) or larger in normal font weight (400), OR 14pt (18.67px) or larger in bold font weight (700). Anything smaller—including 16px body copy and 14px bold buttons—must meet the 4.5:1 Normal Text ratio.

Can I check text layered over a photo or CSS gradient with this tool?

Bramhify's Color Contrast Checker calculates exact ratios between two solid hex colors. For text over hero photos or gradients, sample the lightest pixel behind white text (or darkest pixel behind dark text) and test that worst-case color—or add a translucent dark scrim (rgba(15, 23, 42, 0.72)) behind the text.

Does Pure Black (#000000) on Pure White (#FFFFFF) always give the best UX?

It achieves the mathematical maximum (21:1), which passes every standard, though many users with astigmatism experience visual "halation" (glowing halos) with #FFFFFF text on #000000 in Dark Mode. Using #F8FAFC on #0F172A (17.1:1) still crushes AAA while feeling far gentler during extended reading.

Need to convert HEX/RGB/HSL values or build accessible typography scales?

Pair this tool with our offline HEX, RGB & HSL Color Converter and PX to REM Converter to build consistent, accessible CSS design tokens.


Originally published on Bramhify Guides. Try the interactive 100% offline browser utility directly at bramhify.com.

Top comments (1)

Collapse
 
userxnom profile image
Abdullah Naseer •

The pt-vs-px trap is the most useful line in here — a 14px bold button label needing the full 4.5:1 because the large-text threshold is 14pt (18.67px) bold, not 14px bold, is exactly the kind of detail that passes a design review and then fails the audit.

The hover-state point is the one I'd add to a checklist: a link passing at rest at 4.8:1 and silently dropping below 4.5:1 on :hover is invisible to every tool that only checks the resting state. And the placeholder example is a good catch too — default placeholder grey around 2.4:1 means form hints are unreadable before anyone types a word.

One question: for text over a photo or gradient, you recommend testing the lightest pixel behind white text — do you treat that worst-case pixel as the rule, or do you prefer a scrim (like your rgba(15, 23, 42, 0.72) example) so the text passes against the whole image?