Skip to main content
CSS & Design A11y

Color Contrast & WCAG Accessibility (A11y) Checker

Calculate foreground and background contrast ratios to guarantee WCAG 2.1 AA and AAA compliance for normal text, large text, and graphical UI components.

Precise calculation of WCAG 2.1 contrast ratios (from 1:1 up to 21:1)
Instant AA and AAA compliance scoring for Normal Text, Large Text, and UI Components
Relative luminance calculations per W3C Web Content Accessibility Guidelines formulas
Interactive lightness adjustment slider to automatically reach required contrast thresholds
Color blindness simulation filters: Protanopia, Deuteranopia, Tritanopia, and Achromatopsia
Sponsored Ad Zone

Clean, non-intrusive developer tools sponsor zone. Zero cumulative layout shift.

Comprehensive Technical Manual

The Ultimate Guide to WCAG Color Contrast & Accessible Digital Design

In-depth specifications, architectural mechanics, real-world code implementations, and industry best practices.

01

WCAG 2.1 Conformance Levels: Understanding AA and AAA Standards

  • Web Content Accessibility Guidelines (WCAG) 2.1 establish legal and ethical standards for digital inclusivity. Contrast requirements are categorized into two tiers:
  • Level AA (Global Standard): Requires a minimum 4.5:1 ratio for normal body text (<18pt or <14pt bold) and 3:1 for large text (>=18pt or >=14pt bold) and active UI components/borders.
  • Level AAA (Enhanced Standard): Requires a minimum 7:1 ratio for normal text and 4.5:1 for large text.
  • Failing these thresholds makes digital products difficult or impossible to read for users with low vision, color blindness, or situational impairments (such as bright sunlight).
Implementation Example
// WCAG 2.1 Minimum Contrast Ratio Thresholds
// Level AA:
// - Normal Text: 4.5:1
// - Large Text (>= 18pt or 14pt bold): 3.0:1
// - UI Components & Graphical Objects: 3.0:1

// Level AAA:
// - Normal Text: 7.0:1
// - Large Text: 4.5:1
02

The Mathematics of Relative Luminance and Contrast Ratio

The W3C contrast ratio formula is defined as (L1 + 0.05) / (L2 + 0.05), where L1 is the relative luminance of the lighter color and L2 is the relative luminance of the darker color. Relative luminance linearizes non-linear sRGB values through gamma expansion and applies human spectral sensitivity coefficients (0.2126 Red + 0.7152 Green + 0.0722 Blue). The 0.05 offset accounts for ambient flare on physical screens.

Implementation Example
// Calculating W3C Relative Luminance in TypeScript
function getRelativeLuminance(r: number, g: number, b: number): number {
  const [R, G, B] = [r, g, b].map((val) => {
    const s = val / 255;
    return s <= 0.03928 ? s / 12.92 : Math.pow((s + 0.055) / 1.055, 2.4);
  });
  return 0.2126 * R + 0.7152 * G + 0.0722 * B;
}

function getContrastRatio(l1: number, l2: number): number {
  const lighter = Math.max(l1, l2);
  const darker = Math.min(l1, l2);
  return (lighter + 0.05) / (darker + 0.05);
}
03

Designing Accessible Palettes for Color Vision Deficiencies

Over 8% of men and 0.5% of women experience Color Vision Deficiency (CVD). Protanopia (red-blind), Deuteranopia (green-blind), and Tritanopia (blue-blind) impair hue distinction. In accessible UI design, color must never be the sole visual indicator of status or error. Always pair color cues with icons, text labels, and structural underlines.

Implementation Example
<!-- Accessible Form Field with Icon & High Contrast Text -->
<div class="space-y-1">
  <label for="email" class="text-sm font-medium text-slate-200">Email Address</label>
  <div class="relative">
    <input id="email" aria-invalid="true" aria-describedby="email-err" class="w-full px-3 py-2 border-2 border-rose-500 bg-slate-900 text-white rounded-lg" />
  </div>
  <!-- Not just red color: includes descriptive icon & error copy -->
  <p id="email-err" class="flex items-center gap-1 text-xs text-rose-400 font-medium mt-1">
    <span>⚠️ Please enter a valid email address.</span>
  </p>
</div>
04

Automating Contrast Audits in CI/CD and Semantic Tokens

To prevent accessibility regressions, design systems construct semantic color pairs (--bg-surface and --text-primary) that are mathematically guaranteed to pass WCAG AA. Automated auditing tools like axe-core, Pa11y, and Lighthouse enforce these checks during automated pull request testing.

Implementation Example
/* Semantic Tokens Guaranteed for AA Compliance */
:root {
  --bg-canvas: #090a0f;
  --text-primary: #f8fafc;   /* 18.5:1 Contrast Ratio (AAA) */
  --text-secondary: #94a3b8; /* 6.8:1 Contrast Ratio (AA) */
  --text-muted: #64748b;     /* 3.8:1 (Only for non-text UI boundaries) */
}
Knowledge Base & Clarifications

Frequently Asked Questions: Color Contrast Checker

Got questions about how Color Contrast Checker operates, client-side cryptographic safety, or performance limits? Explore common answers below.

Complementary Utilities
View all in CSS & Design →