TToolbox
◐

Contrast Checker

Check WCAG color contrast

About this tool

Color Contrast measures the relative luminance difference between text and its background, serving as the core benchmark for Web Content Accessibility Guidelines (WCAG 2.1, ISO/IEC 40500). Millions of visually impaired, color-blind, and aging users struggle with low-contrast UI elements, especially under outdoor glare. This tool calculates exact mathematical contrast ratios (ranging from 1:1 to 21:1), testing for WCAG AA and AAA compliance across normal and large text.

How to Use This Tool (Step-by-Step)

1

Enter Text & Background Colors

Input your text foreground color and container background color using HEX or RGB values, or sample with color pickers.

2

Inspect Ratio & WCAG Badges

The engine computes the mathematical contrast ratio (e.g., `4.85:1`), instantly displaying Pass/Fail badges for WCAG AA and AAA.

3

Review Real-Time Typography Mockup

Review live typography mockups across normal body copy, bold headings, and interface icons. Fine-tune lightness to hit compliance.

Official WCAG 2.1 Relative Luminance

Implements official sRGB gamma decompression and luminance weighting formulas, aligned 100% with enterprise accessibility audits.

Full AA & AAA Multi-Level Tiers

Tests across all granular thresholds: Normal text (≥4.5:1 AA), Large text (≥3:1 AA), and enhanced AAA standards (≥7:1 body text).

100% Client-Side Privacy

Calculations run exclusively inside local browser memory. Unreleased brand identity palettes remain completely secure.

Inclusive Design Best Practices & Contrast Tips

  • •Fix ultra-light input placeholders: Grey placeholder copy frequently dips below 2:1 contrast. Darken placeholder hints to `#64748b` to remain readable.
  • •Disabled controls are legally exempt from 4.5:1: Inactive elements do not mandate contrast thresholds to avoid confusing users about clickability.
  • •Fastest compliance tweak: Keep Hue and Saturation identical; only modulate Lightness in HSL to satisfy AA thresholds without redesigning palettes.

Code & Transformation Examples

Common UI Color Pairing Contrast Ratio Benchmark

Color Combinations
• 黑字配白底 (#000000 / #ffffff) : 对比度 21:1 (最高极限,全满分通过 AAA)
• 经典主色 (#4f46e5 / #ffffff) : 对比度 5.23:1 (符合 AA 正文要求)
• 浅灰配白底 (#94a3b8 / #ffffff) : 对比度 2.65:1 (未通过!正文严禁使用)
• 深灰配浅蓝 (#1e293b / #e0e7ff) : 对比度 11.8:1 (完美通过 AAA 级)
WCAG Thresholds
• AA 级 (法定基础及格线) : 普通正文 ≥ 4.5:1 ;18pt(24px)大标题 ≥ 3.0:1
• AAA 级 (增强卓越标准)  : 普通正文 ≥ 7.0:1 ;18pt(24px)大标题 ≥ 4.5:1

* International regulations legally require public sector portals to satisfy WCAG AA contrast standards.

JavaScript WCAG Contrast Calculation Implementation

Relative Luminance Snippet
function getLuminance(r, g, b) {
  const a = [r, g, b].map(v => {
    v /= 255;
    return v <= 0.03928 ? v / 12.92 : Math.pow((v + 0.055) / 1.055, 2.4);
  });
  return a[0] * 0.2126 + a[1] * 0.7152 + a[2] * 0.0722;
}
Calculate Ratio
function getContrast(rgb1, rgb2) {
  const l1 = getLuminance(...rgb1);
  const l2 = getLuminance(...rgb2);
  const lighter = Math.max(l1, l2);
  const darker = Math.min(l1, l2);
  return (lighter + 0.05) / (darker + 0.05);
}

* Human eyes are most sensitive to green (0.7152), dominating luminance calculations.

Frequently Asked Questions

Q: Why does the contrast ratio formula add 0.05?

A: The +0.05 constant simulates ambient room glare reflections and prevents division-by-zero math errors when evaluating pitch-black surfaces.

Q: Do dark background containers have different contrast thresholds?

A: The ratio is symmetrical. Whether light-on-dark or dark-on-light, the brighter luminance is always divided by the darker, requiring the same 4.5:1 ratio.

Q: What are the commercial benefits of WCAG AA compliance?

A: Reduces user bounce rates under sunlight, avoids expensive ADA legal accessibility lawsuits in North America, and boosts enterprise ESG compliance.

Related Tools

All processing happens locally in your browser. Your data is never uploaded to a server.
/