Contrast Checker
Visually audit color contrast ratios between text overlays and backgrounds under WCAG 2.1 specifications, simulate color blindness, and auto-correct to accessible values.
In user interface (UI) and user experience (UX) design, color is more than a branding element—it is a functional vehicle for transferring information. If page typography lacks sufficient contrast against its backing canvas, the interface becomes difficult or impossible to read. Accessibility is a fundamental pillar of modern front-end engineering. Creating inclusive designs ensures that websites are fully usable by individuals with varying degrees of vision impairment, including color vision deficiencies, low vision, and age-related visual degradation.
Our Contrast Checker is a professional-grade web utility designed to simplify the audit and correction of UI color combinations. Built for front-end developers, product managers, web accessibility specialists, and UI/UX designers, it calculates WCAG 2.1 compliance parameters, simulates multiple types of color blindness in real time, automatically suggests conforming colors, and exports clean design tokens.
1. What is Color Contrast?
Color contrast represents the difference in luminance (reflected light) between two adjacent colors—specifically, the foreground text color and the background color. Web browsers render typography on top of containers, and if the luminance difference is too narrow, the letters blur into the background.
To formalize this, the World Wide Web Consortium (W3C) established the Web Content Accessibility Guidelines (WCAG). Contrast compliance is measured as a mathematical ratio ranging from 1:1 (zero contrast, e.g. white text on a white background) to 21:1 (maximum contrast, e.g. solid black text on a solid white background).
2. Understanding WCAG Compliance Levels
The WCAG 2.0/2.1 standards establish three main levels of compliance—A, AA, and AAA. For color contrast, focus is directed on levels AA and AAA:
WCAG Level AA (Minimum Standard)
This is the baseline standard for most commercial, corporate, and educational websites. To pass level AA:
- Normal Text: Typography smaller than
18pt(or14ptbold) must have a contrast ratio of at least4.5:1. - Large Text: Typography that is
18pt(approx.24px) and larger, or14pt(approx.18.66px) bold and larger, must have a contrast ratio of at least3.0:1. - Graphical Objects & User Interface Components: Active inputs, buttons, and decorative graphs require a contrast ratio of at least
3.0:1against surrounding pixels.
WCAG Level AAA (Enhanced Standard)
This is a more stringent standard, required for public services, government platforms, and highly inclusive products. To pass level AAA:
- Normal Text: Typography smaller than
18pt(or14ptbold) must have a contrast ratio of at least7.0:1. - Large Text: Typography that is
18pt(approx.24px) and larger, or14pt(approx.18.66px) bold and larger, must have a contrast ratio of at least4.5:1.
3. Mathematical Formula for Relative Luminance
The contrast ratio between two colors is computed using their relative luminance. Luminance is a measure of the perceived brightness of a color, normalized between 0 (darkest black) and 1 (brightest white).
Step 1: Normalize RGB Channels
For each channel (Red, Green, Blue) in a color, normalize the values between 0 and 1 by dividing by 255:
const sR = R / 255;
const sG = G / 255;
const sB = B / 255;
Step 2: Apply Gamma Correction
Human eyes do not perceive color brightness linearly. Adjust the normalized channels:
const r = sR <= 0.03928 ? sR / 12.92 : Math.pow((sR + 0.055) / 1.055, 2.4);
const g = sG <= 0.03928 ? sG / 12.92 : Math.pow((sG + 0.055) / 1.055, 2.4);
const b = sB <= 0.03928 ? sB / 12.92 : Math.pow((sB + 0.055) / 1.055, 2.4);
Step 3: Compute Relative Luminance
Use the weighted spectral sensitivities of the human eye for Red, Green, and Blue light:
const L = 0.2126 * r + 0.7152 * g + 0.0722 * b;
Step 4: Calculate the Contrast Ratio
Given the luminance values of the lighter color (L1) and the darker color (L2), the ratio is:
const ratio = (L1 + 0.05) / (L2 + 0.05);
The constant addition of 0.05 acts as a visual threshold, simulating light scattering in the eye and preventing divide-by-zero errors when dealing with black.
4. Visual Impairment & Color Blindness Simulations
Web accessibility must account for vision deficiencies. Roughly 8% of men and 0.5% of women worldwide have some form of color vision deficiency (CVD).
Our tool simulates four major types of color blindness directly over components using hardware-accelerated SVG matrix filters:
- Protanopia (Red-blind): A complete lack of red photoreceptors. Red colors appear dark, greenish, or brown, while green and red blends look yellow.
- Deuteranopia (Green-blind): A complete lack of green photoreceptors. This is the most common form of color blindness. Reds and greens are highly confused.
- Tritanopia (Blue-blind): A complete lack of blue photoreceptors. Blue appears greenish, and yellow looks pink or violet.
- Achromatopsia (Monochrome): Complete color blindness. The user perceives only grayscale values of lightness and shadow. Contrast checking is critical here, as legibility relies entirely on luminance difference.
5. Smart Contrast Correction Algorithms
When a color combination fails WCAG compliance, designers shouldn't have to guess how to fix it. Our tool implements a Smart Suggestions Algorithm that programmatically shifts colors to the closest compliant shade.
The Correction Process:
- The algorithm converts the foreground or background color to HSL (Hue, Saturation, Lightness).
- If the background color is light (
L >= 50%), the algorithm decreases the lightness of the foreground color progressively (e.g. by 1% steps) until the target ratio (4.5 or 7.0) is hit. - If the background color is dark (
L < 50%), it increases the lightness of the foreground color until it conforms. - This finds the mathematically closest conforming color, preserving the original hue and saturation as much as possible.
6. Tailwind CSS & Inclusive Design Tokens
Tailwind CSS makes it simple to construct accessible color tokens. Avoid assigning colors ad-hoc (like text-gray-400 bg-white). Instead, configure cohesive, audited design tokens inside your Tailwind config:
// tailwind.config.js
module.exports = {
theme: {
extend: {
colors: {
accessible: {
body: '#1e293b', // Audited 10.4:1 contrast against white
muted: '#64748b', // Audited 4.6:1 contrast against white (passes AA)
bg: '#f8fafc',
brand: '#16a34a' // Audited green passing AA on dark backgrounds
}
}
}
}
}
Using verified variables guarantees compliance across components, headers, buttons, and alert states.
How to Use Contrast Checker
Input your text foreground color and background color using the HEX boxes or RGB/HSL sliders.
Inspect the resulting Contrast Ratio score (e.g. 5.6:1) and the WCAG AA/AAA compliance checkmarks.
If any test fails, click the 'Fix to AA' or 'Fix to AAA' button to auto-shift the color to the nearest conforming HSL value.
Navigate between the preview tabs (Typography, SaaS Form, Dashboard, Buttons) to inspect legibility.
Use the Color Blindness dropdown to simulate how the color scheme is perceived by color-deficient users.
Adjust font sizes and weights in the Typography preview to check large text threshold rules.
Copy the accessible hex color codes, copy Tailwind class mappings, or export the SCSS variables to your project.
Real Examples
Accessible Light Mode Text
Standard body text color designed to pass level AAA standards on a white page.
Foreground: #27272a, Background: #ffffffContrast Ratio: 13.5:1 (Passes WCAG AA Normal, WCAG AAA Normal, AA Large, AAA Large)Compliant Muted Muted Gray Link
A secondary gray link color designed to pass minimum level AA contrast thresholds.
Foreground: #64748b, Background: #ffffffContrast Ratio: 4.6:1 (Passes WCAG AA Normal, WCAG AA Large, WCAG AAA Large; Fails WCAG AAA Normal)Frequently Asked Questions
What is color contrast in web accessibility?
What is the relative luminance formula?
What is the difference between WCAG AA and AAA standards?
What text size qualifies as 'Large Text' under WCAG rules?
How does the smart contrast suggestion feature work?
How do I use color blindness simulations?
Why does neumorphic UI design fail contrast guidelines?
Can I use alpha transparency colors in this tool?
How do I register accessible colors in my Tailwind CSS project?
Is this checker mobile-friendly?
Key Features
- Precise color contrast ratio calculator under WCAG 2.0 / 2.1 compliance algorithms
- Dual color panels supporting native color sliders, custom HEX inputs, RGB controls, and HSL levels
- W3C level AA and level AAA compliance indicators for normal text, large headings, and graphical elements
- Smart Suggestions auto-correcting color lightness to conforming contrast levels with one click
- Color vision deficiencies simulator representing Protanopia, Deuteranopia, Tritanopia, and Achromatopsia
- Sandbox component previews displaying the color pair on headings, buttons, forms, tables, pricing plans, and mobile app UI
- Font customization tools adjusting preview text sizes and weights to audit typography variations
- History logger and favorites bookmarking system saving audited palettes in local storage
- Exports snippets for CSS variables, SCSS variables, JSON configs, and Tailwind CSS configuration parameters
- EyeDropper API color sampler integration for supported desktop web browsers
Common Use Cases
- Auditing brand color palettes to verify level AA standard compliance before launch
- Finding the closest accessible gray shade for secondary text fields on light landing pages
- Simulating how a SaaS dashboard layout appears to users with Deuteranopia or Achromatopsia
- Generating contrast-safe background-foreground pairs for web buttons and active states
- Exporting a compliant color tokens system into Tailwind CSS extend configurations
- Prototyping responsive typography sizes and weights while testing readability ranges
- Restoring previous accessibility audits from local history logs during design reviews