Skip to main content

WCAG Contrast Checker

Check color contrast ratios for WCAG 2.1 accessibility compliance (AA/AAA). Enter values for instant results with step-by-step formulas.

Share this calculator

Formula

Contrast Ratio = (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 L = 0.2126R + 0.7152G + 0.0722B, using linearized sRGB values. The ratio ranges from 1:1 (no contrast) to 21:1 (maximum: black on white).

Worked Examples

Example 1: Corporate Website Body Text

Problem: A website uses #767676 gray text on #FFFFFF white background for body copy at 16px. Check WCAG compliance and suggest fixes if needed.

Solution: Step 1: Calculate contrast ratio\nForeground: #767676 → RGB(118, 118, 118)\nBackground: #FFFFFF → RGB(255, 255, 255)\n\nStep 2: Calculate relative luminance\nL_fg = 0.2126(0.18) + 0.7152(0.18) + 0.0722(0.18) = 0.184\nL_bg = 1.0 (white)\n\nStep 3: Calculate ratio\nRatio = (1.0 + 0.05) / (0.184 + 0.05) = 4.49:1\n\nStep 4: Check requirements for normal text (16px)\nWCAG AA requires 4.5:1 → FAIL (4.49 < 4.5)\nWCAG AAA requires 7:1 → FAIL (4.49 < 7)\n\nStep 5: Find passing color\nDarken foreground to #757575 (4.5:1) for AA\nDarken to #595959 (7.0:1) for AAA\n\nNote: #767676 is often called the 'minimum contrast gray' but actually fails by a tiny margin.

Result: FAILS AA by 0.01 | Change to #757575 for AA | Change to #595959 for AAA

Example 2: Call-to-Action Button

Problem: A CTA button uses white text (#FFFFFF) on bright blue background (#3B82F6). The button text is 16px bold. Verify compliance.

Solution: Step 1: Calculate contrast\nForeground: #FFFFFF → RGB(255, 255, 255)\nBackground: #3B82F6 → RGB(59, 130, 246)\n\nStep 2: Calculate luminance\nL_fg = 1.0 (white)\nL_bg = 0.2126(0.054) + 0.7152(0.216) + 0.0722(0.905) = 0.232\n\nStep 3: Calculate ratio\nRatio = (1.0 + 0.05) / (0.232 + 0.05) = 3.72:1\n\nStep 4: Check requirements\n16px bold = Large text (14pt+ bold threshold)\nLarge text AA requires 3:1 → PASS (3.72 > 3)\nLarge text AAA requires 4.5:1 → FAIL (3.72 < 4.5)\n\nStep 5: For AAA compliance\nDarken blue to #2563EB (4.5:1) or\nUse 18px+ text to ensure large text status\n\nThe button passes AA for large text but fails AAA.

Result: PASSES AA (large text) at 3.72:1 | For AAA: darken to #2563EB or increase to 18px+

Example 3: Form Error Message

Problem: An error message uses #FF6B6B (light red) text on #FFFFFF background at 14px regular weight. This must be readable by all users.

Solution: Step 1: Calculate contrast\nForeground: #FF6B6B → RGB(255, 107, 107)\nBackground: #FFFFFF → RGB(255, 255, 255)\n\nStep 2: Calculate luminance\nL_fg = 0.2126(1.0) + 0.7152(0.137) + 0.0722(0.137) = 0.318\nL_bg = 1.0\n\nStep 3: Calculate ratio\nRatio = (1.0 + 0.05) / (0.318 + 0.05) = 2.85:1\n\nStep 4: Check requirements\n14px regular = Normal text\nNormal text AA requires 4.5:1 → FAIL (2.85 < 4.5)\n\nStep 5: Find accessible red\nDarken to #DC2626 for 4.5:1 (AA)\nDarken to #991B1B for 7:1 (AAA)\n\nCritical: Error messages must be highly accessible as they convey important information. Consider also using an icon or bold text to not rely solely on color.

Result: FAILS AA at 2.85:1 | Use #DC2626 for AA | Use #991B1B for AAA | Add icon for redundancy

Frequently Asked Questions

What is WCAG and why does contrast matter?

WCAG (Web Content Accessibility Guidelines) are international standards for web accessibility published by W3C. Adequate color contrast is crucial because approximately 300 million people worldwide have color vision deficiencies, and many more have low vision. Poor contrast makes text difficult or impossible to read for these users. WCAG 2.1 Level AA is the legal requirement in many jurisdictions, including under the ADA (US), EN 301 549 (EU), and similar laws globally.

What are the WCAG contrast ratio requirements?

WCAG 2.1 has three conformance levels: Level A (minimum), Level AA (recommended), and Level AAA (enhanced). For contrast: Normal text needs 4.5:1 for AA and 7:1 for AAA. Large text (18pt+ or 14pt+ bold) needs 3:1 for AA and 4.5:1 for AAA. Graphical objects and UI components need 3:1 for AA. Logos and decorative text are exempt. The maximum possible ratio is 21:1 (black on white or vice versa).

How is contrast ratio calculated?

Contrast ratio is calculated using relative luminance: Ratio = (L1 + 0.05) / (L2 + 0.05), where L1 is the lighter color's luminance and L2 is the darker. Relative luminance uses the formula: L = 0.2126R + 0.7152G + 0.0722B, where R, G, B are linearized sRGB values. The coefficients reflect human eye sensitivity (most sensitive to green, least to blue). This produces ratios from 1:1 (no contrast) to 21:1 (maximum).

What counts as 'large text' under WCAG?

Large text is defined as: 18 points (24px) or larger for regular weight, OR 14 points (18.66px) or larger for bold weight. Large text has lower contrast requirements (3:1 for AA vs 4.5:1) because larger characters are inherently more readable. Note: these are minimum sizes—many accessibility experts recommend even larger text for optimal readability, especially for body copy.

What about contrast for non-text elements?

WCAG 2.1 Success Criterion 1.4.11 requires 3:1 contrast for: UI components (buttons, form fields, focus indicators), graphical objects (icons, charts), and any element required to understand content. This means a button's border or background must have 3:1 contrast with its surroundings, and icons must be distinguishable. Disabled elements are exempt, but their disabled state should still be perceivable.

How do I fix low contrast issues?

Options include: 1) Darken the foreground color—this usually preserves brand identity better than lightening backgrounds. 2) Lighten the background—good for colored backgrounds with dark text. 3) Increase font size—larger text has lower contrast requirements. 4) Increase font weight—bold text at 14pt+ qualifies as large text. 5) Add a text shadow or outline in high-contrast color. 6) Use a semi-transparent overlay between text and image backgrounds.

Background & Theory

The WCAG Contrast Checker Calculator applies the following established principles and formulas. Large language models process text by breaking it into tokens, sub-word units produced by algorithms such as byte-pair encoding. In English, one token approximates four characters or three-quarters of a word on average, though this ratio varies considerably across languages and code. A 1000-word document typically requires around 1300 to 1500 tokens. Token count drives both context window constraints and inference billing, making accurate estimation essential for budgeting API usage. The capability of a neural network scales primarily with its parameter count. Parameters are the numerical weights adjusted during training via gradient descent. GPT-3 contains 175 billion parameters; larger models in the trillion-parameter range require correspondingly greater compute and memory. Training compute is measured in floating-point operations (FLOPs): the Chinchilla scaling laws derived by Hoffmann et al. in 2022 show that optimal training allocates roughly 20 tokens per parameter, meaning a 70B-parameter model benefits from approximately 1.4 trillion training tokens. Inference latency depends on model size, hardware, and batching strategy. Running a 7B-parameter model in FP16 precision requires roughly 14 GB of GPU VRAM (2 bytes per parameter), while INT8 quantisation halves this to around 7 GB with modest quality loss, and INT4 reduces it to approximately 3.5 GB. This quantisation trade-off between memory, speed, and accuracy is central to deploying models on consumer hardware. Perplexity measures how surprised a language model is by a given text corpus; lower perplexity indicates better predictive accuracy. Embedding dimensions determine the size of the dense vector representations used to encode semantic meaning. Models like OpenAI's text-embedding-ada-002 produce 1536-dimensional vectors, while compact models may use 384 dimensions. Context window size defines the maximum token span a model can attend to in a single forward pass. Extending context windows from 4K to 128K tokens enables document-scale reasoning but substantially increases memory requirements, as the attention mechanism scales quadratically with sequence length without architectural modifications such as flash attention.

History

The history behind the WCAG Contrast Checker Calculator traces back through the following developments. The mathematical neuron model published by Warren McCulloch and Walter Pitts in 1943 first proposed that logical functions could be computed by networks of simple threshold units, planting the seed of neural computation. Frank Rosenblatt's Perceptron, introduced in 1957 and implemented in custom hardware by 1960, could learn linear classifiers from examples and generated enormous public excitement before Marvin Minsky and Seymour Papert's 1969 book rigorously analysed its fundamental limitations, demonstrating it could not learn the simple XOR function. The first AI winter, roughly 1974 to 1980, followed as funding agencies in the US and UK grew disillusioned with unrealised promises. A second wave of interest during the 1980s produced rule-based expert systems deployed in medicine and finance, and saw the re-derivation of backpropagation by Rumelhart, Hinton, and Williams in 1986, making it practical to train multi-layer networks on real problems. A second winter from 1987 to 1993 followed as expert systems proved brittle and hardware remained insufficient for genuine deep learning. The deep learning revival crystallised at the ImageNet Large Scale Visual Recognition Challenge in 2012, when Alex Krizhevsky's convolutional network AlexNet slashed the top-5 error rate by nearly 11 percentage points compared to the prior year's winner. This demonstrated that deep networks trained on GPUs with large labelled datasets could achieve human-competitive image recognition. Subsequent years saw rapid advances in recurrent networks, sequence-to-sequence models, and the attention mechanism, culminating in the transformer architecture introduced by Vaswani et al. in 2017. OpenAI released GPT-1 in 2018, demonstrating that unsupervised pre-training on large text corpora followed by task-specific fine-tuning could transfer knowledge broadly across language tasks. GPT-2 in 2019 demonstrated surprisingly fluent long-form text generation. GPT-3 in 2020, with 175 billion parameters, showed that scale alone could unlock few-shot learning. Kaplan et al.'s 2020 scaling laws paper provided the theoretical grounding. ChatGPT launched in November 2022, reaching one million users within five days and igniting mainstream global awareness of large language models.

References