WCAG Color Contrast Ratio Checker

Test color contrast ratios against WCAG 2.1 AA and AAA accessibility standards for normal text, large text, and UI components.

4.9 / 5· 148 verified ratings
•
100% Client-Side Privacy
•
Verified 2026 Engine
Loading tool engine...
Frequently Used With:UUID / GUID Generator (v4 & v1) →Cron Expression Generator & Schedule Builder →Lorem Ipsum Placeholder Text Generator →HTML Entity Encoder & Decoder →
Institutional-Grade Accuracy & Client-Side Privacy Guarantee

Unlike conventional calculator sites that send your financial numbers, payload data, or code snippets across remote web servers, Affi-Chain processes all mathematical derivations, algorithms, and data parsing 100% locally within your browser sandbox. No tracking cookies, no server-side retention, and zero transmission lag.

What is Color Contrast & Digital Accessibility?

Color Contrast in digital user interface design measures the difference in perceived photometric luminance between foreground visual elements (such as typographic text, interactive buttons, or vector iconography) and their underlying background surface.

Under the Web Content Accessibility Guidelines (WCAG 2.1 and WCAG 2.2) published by the World Wide Web Consortium (W3C), ensuring sufficient color contrast is a mandatory legal and ethical requirement for public web properties under the Americans with Disabilities Act (ADA Title III), Section 508 of the US Rehabilitation Act, and the European Accessibility Act (EAA).

Over 2.2 billion people globally live with vision impairments, including low visual acuity, age-related macular degeneration, diabetic retinopathy, glaucoma, cataracts, and congenital color vision deficiencies (protanopia, deuteranopia, and tritanopia). Furthermore, millions of sighted mobile users navigate digital applications under high ambient sunlight where screen glare washes out subtle color differences. When digital interfaces utilize faint gray text on white backgrounds or subtle pastel buttons, content becomes illegible, causing user abandonment and exposing organizations to costly accessibility lawsuits.


The Mathematical Physics of Color Contrast: Gamma & Luminance

The WCAG contrast ratio is calculated using the physical property of Relative Luminance ($L$), defined under International Electrotechnical Commission standard IEC 61966-2-1 as the relative brightness of any point in a colorspace, normalized to 0 for the darkest black and 1 for the brightest white.

flowchart TD
    HexInput["Input Hex Colors: Foreground (#333) & Background (#FFF)"] --> Normalize["Stage 1: Normalize sRGB integers (0-255) to decimals (0.0 to 1.0)"]
    Normalize --> GammaDecompress["Stage 2: Gamma Decompression to Linear RGB"]
    
    GammaDecompress --> LuminanceFormula["Stage 3: Calculate Photopic Relative Luminance (L)"]
    LuminanceFormula --> Weighting["L = 0.2126 * R_linear + 0.7152 * G_linear + 0.0722 * B_linear"]
    
    Weighting --> OrderLuminance["Identify L_1 (Lighter) and L_2 (Darker)"]
    OrderLuminance --> ContrastRatio["Compute WCAG Contrast Ratio: CR = (L_1 + 0.05) / (L_2 + 0.05)"]
    
    ContrastRatio --> Audit["Stage 4: Audit Against WCAG AA & AAA Thresholds"]

Stage 1: Gamma Decompression to Linear RGB

Digital monitors display colors using non-linear sRGB coordinates. To compute true physical optical luminance, the sRGB values must be converted to linear energy space:

  1. Normalize 8-bit integers ($0 - 255$) into unit fractions: $$R_{\text{sRGB}} = \frac{R}{255}, \quad G_{\text{sRGB}} = \frac{G}{255}, \quad B_{\text{sRGB}} = \frac{B}{255}$$

  2. Apply the sRGB inverse electro-optical transfer function (EOTF): $$C_{\text{linear}} = \begin{cases} \frac{C_{\text{sRGB}}}{12.92} & \text{if } C_{\text{sRGB}} \le 0.04045 \ \left(\frac{C_{\text{sRGB}} + 0.055}{1.055}\right)^{2.4} & \text{if } C_{\text{sRGB}} > 0.04045 \end{cases}$$

(Where $C$ represents $R$, $G$, or $B$.)

Stage 2: Relative Luminance Formula ($L$)

Linear values are multiplied by photopic human spectral sensitivity coefficients:

$$L = 0.2126 \cdot R_{\text{linear}} + 0.7152 \cdot G_{\text{linear}} + 0.0722 \cdot B_{\text{linear}}$$

Human eye physiology accounts for the heavy 71.52% weighting on green light: the human retina contains significantly more M-cones (sensitive to 530nm green wavelengths) than S-cones (blue, 7.22%) or L-cones (red, 21.26%).

Stage 3: The WCAG Contrast Ratio Equation ($CR$)

Let $L_1$ represent the relative luminance of the lighter color, and $L_2$ represent the relative luminance of the darker color ($L_1 \ge L_2$):

$$CR = \frac{L_1 + 0.05}{L_2 + 0.05}$$

The constant $0.05$ represents ambient room light flare reflecting off typical LCD and OLED display glass surfaces. Contrast ratios range from:

  • $1:1$ (Minimum: Identical colors, zero visual contrast)
  • $21:1$ (Maximum: Pure black #000000 against pure white #ffffff)

WCAG Compliance Thresholds: Level AA vs. Level AAA Matrix

WCAG specifies two operational tiers of contrast compliance based on typographic size and semantic role:

UI Element TypeTypographic Threshold CriteriaWCAG Level AA (Mandatory)WCAG Level AAA (Enhanced)Primary Failure Example
Normal Body TextFont size $< 18\text{pt}$ ($24\text{px}$) or $< 14\text{pt}$ bold ($18.66\text{px}$)$\ge 4.5 : 1$$\ge 7.0 : 1$Light gray paragraph text (#999999 on #ffffff = 2.8:1).
Large Text / HeadingsFont size $\ge 18\text{pt}$ ($24\text{px}$) or $\ge 14\text{pt}$ bold ($18.66\text{px}$)$\ge 3.0 : 1$$\ge 4.5 : 1$Thin hero titles on pastel background cards.
UI Components (SC 1.4.11)Button borders, form input outlines, toggle switches$\ge 3.0 : 1$$\ge 4.5 : 1$Input field borders blending into form modal background.
Graphical IconsFunctional icons (magnifying glass search, shopping cart)$\ge 3.0 : 1$$\ge 4.5 : 1$Low-contrast navigation tab icons.
Incidental / DisabledInactive disabled buttons, decorative branding watermarksExemptExemptGrayed-out form submit button prior to validation.

Practical Implementation Examples

Python: Full Gamma Decompression & WCAG Audit Engine

import re
from typing import Tuple, Dict

def hex_to_rgb(hex_code: str) -> Tuple[int, int, int]:
    clean_hex = hex_code.lstrip("#")
    if len(clean_hex) == 3:
        clean_hex = "".join([c * 2 for c in clean_hex])
    return (
        int(clean_hex[0:2], 16),
        int(clean_hex[2:4], 16),
        int(clean_hex[4:6], 16)
    )

def calculate_relative_luminance(rgb: Tuple[int, int, int]) -> float:
    # 1. Normalize sRGB to 0.0 - 1.0
    r_srgb, g_srgb, b_srgb = [c / 255.0 for c in rgb]

    # 2. Decompress gamma to linear space
    def to_linear(c: float) -> float:
        return c / 12.92 if c <= 0.04045 else ((c + 0.055) / 1.055) ** 2.4

    r_lin = to_linear(r_srgb)
    g_lin = to_linear(g_srgb)
    b_lin = to_linear(b_srgb)

    # 3. Spectral Photopic Weighting
    return (0.2126 * r_lin) + (0.7152 * g_lin) + (0.0722 * b_lin)

def evaluate_wcag_contrast(fg_hex: str, bg_hex: str) -> Dict[str, any]:
    lum1 = calculate_relative_luminance(hex_to_rgb(fg_hex))
    lum2 = calculate_relative_luminance(hex_to_rgb(bg_hex))

    lighter = max(lum1, lum2)
    darker = min(lum1, lum2)

    # WCAG Contrast Formula
    contrast_ratio = (lighter + 0.05) / (darker + 0.05)

    return {
        "foreground": fg_hex,
        "background": bg_hex,
        "contrast_ratio": f"{contrast_ratio:.2f}:1",
        "raw_ratio": round(contrast_ratio, 2),
        "wcag_aa_normal_text": contrast_ratio >= 4.5,
        "wcag_aa_large_text": contrast_ratio >= 3.0,
        "wcag_aaa_normal_text": contrast_ratio >= 7.0,
        "wcag_aaa_large_text": contrast_ratio >= 4.5,
        "ui_components_3_to_1": contrast_ratio >= 3.0
    }

# Example: Slate Blue (#475569) on Pure White (#FFFFFF)
audit = evaluate_wcag_contrast("#475569", "#FFFFFF")
for k, v in audit.items():
    print(f"{k.ljust(24)}: {v}")

TypeScript / JavaScript Browser Contrast Validator

export interface WcagResult {
  ratio: number;
  ratioString: string;
  passAaNormal: boolean;
  passAaLarge: boolean;
  passAaaNormal: boolean;
}

export function getContrastRatio(fgHex: string, bgHex: string): WcagResult {
  const parseHex = (hex: string) => {
    const clean = hex.replace('#', '');
    const full = clean.length === 3 ? clean.split('').map(c => c + c).join('') : clean;
    const num = parseInt(full, 16);
    return [(num >> 16) & 255, (num >> 8) & 255, num & 255];
  };

  const getLuminance = (rgb: number[]) => {
    const a = rgb.map(v => {
      const c = v / 255;
      return c <= 0.04045 ? c / 12.92 : Math.pow((c + 0.055) / 1.055, 2.4);
    });
    return 0.2126 * a[0] + 0.7152 * a[1] + 0.0722 * a[2];
  };

  const l1 = getLuminance(parseHex(fgHex));
  const l2 = getLuminance(parseHex(bgHex));
  const ratio = (Math.max(l1, l2) + 0.05) / (Math.min(l1, l2) + 0.05);

  return {
    ratio: Math.round(ratio * 100) / 100,
    ratioString: `${(Math.round(ratio * 100) / 100).toFixed(2)}:1`,
    passAaNormal: ratio >= 4.5,
    passAaLarge: ratio >= 3.0,
    passAaaNormal: ratio >= 7.0
  };
}

Critical Edge Cases & Common Accessibility Pitfalls

1. Alpha Transparency & Layer Compositing

When designers specify semi-transparent colors (e.g. rgba(0, 0, 0, 0.6)), calculating contrast against the raw RGBA values is impossible without knowing the underlying background surface. The foreground color must first be composited over the background using alpha-blending mathematics:

$$C_{\text{composite}} = (\alpha \times C_{\text{fg}}) + ((1 - \alpha) \times C_{\text{bg}})$$

Failing to composite translucent elements causes automated CI/CD accessibility linters (such as Axe-core or Lighthouse) to flag false positives or miss glaring illegibility defects.

2. The Form Placeholder Trap

Browser default styles render input field placeholders in light gray (#757575 or #A0AEC0). When placed inside white input boxes (#FFFFFF), the contrast ratio typically hovers between 2.3:1 and 3.2:1, failing WCAG AA 4.5:1 standards. Users with low vision frequently mistake light placeholders for pre-filled data, submitting blank forms or abandoning purchase checkouts.

3. Relying Exclusively on Color for Semantic Status (WCAG SC 1.4.1)

Even if a red error text (#DC2626) achieves a 4.6:1 contrast ratio against white, using color alone to convey validation status violates WCAG Success Criterion 1.4.1 (Use of Color). A user with protanopia cannot distinguish red error alerts from green success badges without accompanying visual indicators (such as an alert icon ! or explicit text labeling "Error:").

Frequently Asked Questions

What is the minimum WCAG AA contrast ratio for regular text?
WCAG 2.1 Level AA requires a minimum contrast ratio of 4.5:1 for regular text and 3:1 for large text (18pt or 14pt bold).

Explore Related Utilities