What Is Color Contrast Ratio? A Step-by-Step WCAG AA and AAA Calculation with Example Colors
Updated: November 6, 2026 · AracMerkezi
▶ Open Color Contrast Checker (WCAG)
The contrast ratio between text and background color is one of the most important factors in how comfortably a piece of writing can be read. It matters for users with low vision, but also for anyone using a phone in the sun. In this guide we do not stop at giving the thresholds; we show how the ratio is calculated by working through one gray step by step, put the calculated results for common color pairs in a table, and explain why borderline values need care.
What is contrast ratio?
WCAG (the Web Content Accessibility Guidelines) defines the ratio between the relative luminances of two colors as a value between 1:1 and 21:1. Identical colors give 1:1, and black on white gives 21:1. As the ratio increases, readability increases.
Required ratios
| Level | Normal text | Large text |
|---|---|---|
| AA | 4.5:1 | 3:1 |
| AAA | 7:1 | 4.5:1 |
Large text is regular text of about 24 px (18 pt) and above, or bold text of about 18.66 px (14 pt) and above. In practice, the target for most sites should be level AA. For interface parts other than text as well (button borders, form field outlines, icons), a ratio of at least 3:1 against the background is expected. For the rem equivalents of pixel units, see the guide to px, rem and em.
How is the ratio calculated step by step?
The calculation has two stages: first the relative luminance (L) of each color, then the ratio of the two luminances.
- Divide each channel (R, G, B) by 255.
- If the value is 0.03928 or less, divide it by 12.92; if it is larger, raise
((c + 0.055) / 1.055)to the power of 2.4. - Luminance: L = 0.2126 × R + 0.7152 × G + 0.0722 × B.
- Ratio: (L lighter + 0.05) / (L darker + 0.05).
Example 1: #767676 gray on a white background
- All three channels are 118; 118 / 255 = 0.4627.
- ((0.4627 + 0.055) / 1.055)²·⁴ ≈ 0.1812. Because the three channels are equal, the weights add up to 1 and L ≈ 0.1812.
- The luminance of white is 1.
- Ratio = (1 + 0.05) / (0.1812 + 0.05) = 1.05 / 0.2312 ≈ 4.54:1.
The result is just above 4.5; so #767676 is the lightest gray that passes AA on a white background. #777777, one step lighter, comes out at 4.478 and fails for normal text. This small-looking difference shows the danger of rounding to "about 4.5": the comparison is made with the unrounded value.
Example 2: #999999 gray on a white background
Using 153 instead of 118, the channel becomes 0.6, the linear value is ≈ 0.3185, and the ratio comes out as 1.05 / 0.3685 ≈ 2.85:1. This cannot pass even 3, the large-text threshold. Although light gray text looks stylish in a design, it often has insufficient contrast; this is one of the most common accessibility mistakes.
Example 3: Button and text colors
The ratios below were calculated with the WCAG formula and compared with the formula used by the checking tool on the site.
| Text / Background | Ratio | AA normal | AA large | AAA normal |
|---|---|---|---|---|
| Black / White | 21.00:1 | Pass | Pass | Pass |
| #595959 / White | 7.01:1 | Pass | Pass | Pass |
| #6B7280 / White | 4.83:1 | Pass | Pass | Fail |
| #767676 / White | 4.54:1 | Pass | Pass | Fail |
| #777777 / White | 4.48:1 | Fail | Pass | Fail |
| White / #2563EB | 5.17:1 | Pass | Pass | Fail |
| White / #3B82F6 | 3.68:1 | Fail | Pass | Fail |
| #FF0000 / White | 4.00:1 | Fail | Pass | Fail |
| #999999 / White | 2.85:1 | Fail | Fail | Fail |
Takeaway: on a button with white text, a #2563EB background passes AA comfortably, while the slightly lighter #3B82F6 is enough only for large text. Pure red (#FF0000) on white is very close to 4 (3.998) but cannot pass 4.5.
Example 4: The same gray on a different background
Contrast is not a property of a single color but of a pair. The gray #6B7280 gives 4.83:1 on a white background and passes AA. The same gray on a dark background (#111827) gives only 3.67:1 and fails for normal text. If you use gray text in a dark theme, you need a lighter shade: #9CA3AF gives 6.99:1 on the same #111827 background; it passes AA and falls only just short of AAA. A light gray #E5E7EB passes comfortably at 14.33:1. That is why sites with theme switching need to measure the colors separately for each theme.
How can it be improved?
- Darken the text color or lighten the background.
- Use higher contrast for thin and small text.
- Do not use color alone to carry information; in cases such as errors, add an icon or text too.
- When putting text over an image, add a semi-transparent layer.
- Test button and link states (hover, focus) as well.
- If you use a dark theme, check the ratios separately in both themes.
Common mistakes
- Judging the ratio "enough" by eye without measuring.
- Treating a value like 4.48 as 4.5 and counting it as a pass.
- Applying the large-text threshold to all headings; if a heading is not large and bold enough, the normal-text rule applies.
- Skipping not only text but also borders and icons.
- Not measuring the worst point for text over an image or gradient.
- Not testing hover and focus states.
Short glossary
- Relative luminance: The perceived brightness of a color, measured between 0 (black) and 1 (white).
- Normal and large text: Two text classes with different thresholds; determined by size and weight.
- AA and AAA: Conformance levels in WCAG; AA is the target for most projects, and AAA is a stricter level.
- Non-text contrast: The ratio of elements such as button borders, icons and form outlines to the background.
When to use it and its limits
Contrast ratio is a readability measure; it does not guarantee all accessibility. Font, size, line spacing and the user's screen settings matter too. Logos and purely decorative text may be exempt from the thresholds; still, confirm this with your project's or organization's rules. Where legal compliance is required, check the applicable standard and its version in the relevant sources. A practical method: list the colors you will use in a table, measure each pair, replace the ones that fail with a darker or lighter shade, and then check the page again by eye.
The Color Contrast Checker tool calculates the numbers for you and also shows a pass or fail result for the four levels. For choosing colors, take a look at the Web Color Palette Guide, and for the RGB equivalent of HEX codes, the HEX and RGB guide.
Frequently asked questions
What contrast ratio is required for AA?
At least 4.5:1 for normal text and 3:1 for large text.
How is large text defined?
Regular text of about 24 px and above, or bold text of 18.66 px and above.
What is the contrast of black on white?
21:1, the highest possible value.
Tools mentioned in this guide
More guides
- How to Choose a Color Palette for a Website: Building a Full Palette From One Color – How to choose a website color palette: build tints, accents and neutrals from one HEX color, with the 60-30-10 rule, contrast values and CSS variables.
- How to Convert HEX to RGB Color Codes: Step-by-Step Examples – How to convert a HEX color code to RGB and back: hexadecimal basics, short and 8-digit HEX, darkening math and verified JavaScript and Python snippets.
- What Is the Difference Between PX, REM and EM? CSS Units, a Conversion Table and Which to Use When – What is the difference between px, rem and em in CSS, and which to use when? The px-to-rem formula, an em compounding example and a 16 px conversion table.
- How to Make Fluid Font Sizes with CSS clamp(): Formula, Ready Values and Glassmorphism – How is CSS clamp(min, preferred, max) calculated? The formula for fluid type between two screen widths, 3 worked examples, rem and accessibility notes.
- How to Make Glassmorphism (Frosted Glass Effect) With CSS – How do you make a frosted glass effect with CSS? backdrop-filter, semi-transparent background, border and shadow values, plus support and contrast tips.
This article is for general information only and is not legal, financial or medical advice. We are not an official institution.