Contrast Ratio Calculator - WCAG 2 AA and AAA Color Checker

Use this contrast ratio calculator to score any two hex colors against the WCAG 2 AA and AAA contrast thresholds for body text, large text, and UI components.

Updated: June 19, 2026 • Free Tool

Contrast Ratio Calculator

Hex value for the text or icon. The leading # is optional; 3-digit shorthand like #09c is accepted.

Hex value for the surface behind the text. Use the same shorthand rules as the foreground.

WCAG 2 defines large text as 18pt regular or 14pt bold, which lowers the AA threshold from 4.5:1 to 3:1.

Results

Contrast ratio
0:1
Sample text on sample background
WCAG AA, normal text (4.5:1) 0
WCAG AA, large text (3:1) 0
WCAG AAA, normal text (7:1) 0
WCAG AAA, large text (4.5:1) 0
Relative luminance (L1 / L2) 0

What Is a Contrast Ratio Calculator?

A contrast ratio calculator answers the one accessibility question that matters before any text or icon ships: do these two colors meet the WCAG 2 contrast thresholds for the people who will read them? Enter a foreground hex color and a background hex color, and the contrast ratio calculator returns the contrast ratio, the relative luminance of both colors, and a pass/fail badge for AA normal text at 4.5:1, AA large text at 3:1, AAA normal text at 7:1, and AAA large text at 4.5:1.

  • Audit body text on a marketing page: Score headline, body, link, and button colors against the 4.5:1 AA threshold.
  • Validate form fields and placeholders: Check borders, labels, helper text, and field background to catch low-contrast forms.
  • Compare dark mode and light mode pairs: Run brand colors through both backgrounds to confirm both clear the WCAG AA grid.
  • Check icon and UI component contrast: Score icons, focus rings, and disabled states against the 3:1 non-text threshold.

The contrast ratio is a single number that captures how different two colors look on a backlit screen, so the calculator gives a quick yes/no on whether a color pair is safe to ship. The 0.05 offset models ambient screen flare and yields a 21:1 upper bound for pure black on pure white.

Treat the contrast ratio calculator as the planning step before a design token lands in code. When a pair is borderline, sample the colors on a real display at the intended font size before committing.

If a brand color is defined as rgb() instead of hex, the same channel math feeds the RGB to Hex calculator so the pair can be reused across CSS and design tokens.

How the Contrast Ratio Calculator Works

The contrast ratio calculator is built in three steps: parse each hex into sRGB channels, run those channels through the inverse sRGB companding curve, then combine the linear channels into a single relative luminance and feed both luminances into the contrast formula.

For each sRGB channel c in [0, 1]: c_lin = c / 12.92 if c <= 0.04045, else ((c + 0.055) / 1.055) ^ 2.4. Relative luminance L = 0.2126 R_lin + 0.7152 G_lin + 0.0722 B_lin. Contrast ratio = (max(L1, L2) + 0.05) / (min(L1, L2) + 0.05).
  • Foreground (hex): Hex value for the text or icon, with or without the leading #.
  • Background (hex): Hex value for the surface behind the foreground.
  • Large text toggle: Switches the AA pass threshold from 4.5:1 to 3:1 for 18pt regular or 14pt bold text.
  • Relative luminance (L): Perceived brightness of each color after sRGB inverse companding, on a [0, 1] scale.
  • Contrast ratio: (L1 + 0.05) / (L2 + 0.05) with L1 as the higher luminance, returned to two decimals.

Hex shorthand like #09c expands to #0099cc before the math runs, matching CSS behavior. Lowercase and uppercase hex digits normalize to the same value, and the large text toggle only changes which AA badge is highlighted, not the ratio itself.

Dark slate body text on white

Foreground #1f2937, background #ffffff, normal text.

R_lin = 0.0137, G_lin = 0.0222, B_lin = 0.0383, L2 = 0.0216. Ratio = (1.05) / (0.0716) = 14.68.

Contrast ratio 14.68, passes WCAG 2 AAA at every level.

Dark slate on white clears the 7:1 AAA threshold, so body copy and small UI text all pass.

Mid gray on white at the AA boundary

Foreground #777777, background #ffffff, normal text.

L1 = 1.0000, L2 = 0.1820. Ratio = (1.05) / (0.2320) = 4.48.

Contrast ratio 4.48, fails WCAG 2 AA for normal text but passes for large text.

A common mid-tone gray fails the AA body-text threshold. Use larger or darker text on this pair.

Indigo link on a light gray card

Foreground #2563eb, background #f3f4f6, normal text.

L1 = 0.9131, L2 = 0.1713. Ratio = (0.9631) / (0.2213) = 4.70.

Contrast ratio 4.70, passes WCAG 2 AA for normal text.

A saturated link color on a near-white card sits just above the AA boundary.

According to WCAG 2.2, the contrast ratio is (L1 + 0.05) / (L2 + 0.05), with L1 as the higher luminance.

According to WCAG 2.2, relative luminance comes from sRGB channels normalized to [0, 1], run through the inverse companding curve at the 0.04045 breakpoint, and combined with the weights 0.2126, 0.7152, and 0.0722.

When the hex shorthand needs to be expanded into channels by hand, the Hex to RGB calculator shows the same expansion step the contrast calculator runs internally.

Key Concepts Explained

Four ideas drive every contrast decision and the pass/fail badges.

Relative luminance (L)

The perceived brightness of a color under the standard sRGB viewing model. Each channel is normalized to [0, 1], run through the inverse sRGB companding curve with the 0.04045 breakpoint, then combined with the Rec.709 weights 0.2126, 0.7152, and 0.0722.

Contrast ratio

(L1 + 0.05) / (L2 + 0.05) with L1 as the higher luminance. The result is always between 1 and 21.

WCAG 2 AA thresholds

AA requires 4.5:1 for normal text and 3:1 for large text (18pt regular or 14pt bold) and essential UI components.

WCAG 2 AAA thresholds

AAA tightens the rule to 7:1 for normal text and 4.5:1 for large text, the right target for low-vision readers.

Relative luminance is not the same as lightness in HSL or CIELAB. It is the linearized light output of a display, so saturated colors with the same HSL lightness can still land on different contrast ratios. Large text relaxes the AA rule because larger letterforms are easier to read at lower contrast; WCAG defines large text as 18 point regular or 14 point bold, which a 16px body font is not.

When the sRGB weight on the green channel feels unintuitive, the Color Converter exposes the same RGB channels as HSL and HSV so the eye can compare the two models.

How to Use This Calculator

Six steps take you from two hex values to a WCAG 2 pass/fail decision.

  1. 1 Paste the foreground hex color: Type the hex value for the text or icon. The leading # is optional and 3-digit shorthand like #09c is accepted.
  2. 2 Paste the background hex color: Type the hex value for the surface behind the text. Use the same shorthand rules as the foreground.
  3. 3 Pick normal text or large text: Set the large text toggle to Yes for 18pt regular or 14pt bold text, where the AA threshold drops from 4.5:1 to 3:1.
  4. 4 Read the contrast ratio: Use the contrast ratio to compare the pair against the WCAG 2 grid. A ratio of 4.50 or higher passes AA for normal text.
  5. 5 Check the AA and AAA badges: Each threshold gets its own pass/fail badge so the relevant decision for your text size is obvious at a glance.
  6. 6 Swap and recheck: Swap the two hex values to confirm the ratio is symmetric. If a pair is borderline, sample the colors on a real display before committing.

Check the body text on a marketing page: paste the text hex (#1f2937) and the page background (#ffffff), leave large text on No, and read the contrast ratio of 14.68. Every WCAG 2 threshold passes, so the copy is safe to ship.

Once the colors are locked, the Pixel to Em/Rem converter picks the matching rem and em sizes so the body copy sits inside the WCAG large-text threshold without a redesign.

Benefits of Using This Calculator

Six practical wins show up the first time a color pair goes through the calculator instead of the eyeball.

  • Catch low-contrast copy before it ships: Score the actual text and background hex values, so a failing pair never reaches staging.
  • Audit a whole design system in minutes: Loop through the design tokens once and record the pass/fail badge next to each.
  • Resolve design disagreements with one number: Replace 'this feels too low contrast' with a clear AA or AAA decision.
  • Stay current with the WCAG 2 standard: The thresholds and formulas come straight from the WCAG 2.2 definition.
  • Cover both modes in one pass: Run the same brand colors against light and dark backgrounds before branching the design system.
  • Document accessibility decisions in the ticket: Paste the ratio and the pass/fail into the design review for an audit trail.

When the audit has to extend across the actual hardware readers use, the Screen Resolution calculator turns panel size and resolution into PPI so each pair can be sampled at the real pixel density of the device.

Factors That Affect Your Results

Five factors shift the ratio and pass/fail badges in real designs.

Font size and weight

Larger or bolder text reads more clearly at lower contrast, which is why the AA threshold drops from 4.5:1 to 3:1 for 18pt regular or 14pt bold text.

Display calibration and ambient light

A dim or warm display lowers the effective contrast of the same hex pair, so sample colors on the hardware the audience uses most.

Color blindness and tinted vision

Two colors that look different to most viewers can collapse for someone with deuteranopia or protanopia, so contrast alone is not enough.

Surrounding content and visual noise

Text that sits next to imagery or busy backgrounds feels lower contrast than the same pair in a blank panel.

Alpha and translucency

The formula assumes solid colors, so a hex at 70% alpha will not produce the ratio the calculator returns for the same hex at 100%.

  • The WCAG 2 contrast formula was designed for solid text on a solid background and does not cover gradient text, drop shadows, or outline text.
  • Translucent or anti-aliased text mixes with the surface behind it, so the contrast ratio is the upper bound at full opacity.
  • The 0.05 ambient flare offset was tuned for backlit displays and may understate contrast on paper or e-ink.

Treat the contrast ratio as the lowest acceptable score for a color pair. Anything borderline should be sampled on a real display at the intended size before the design is locked. For non-text content like icons and form borders the 3:1 threshold is the relevant pass value.

According to WebAIM, color contrast is one of the most reliable accessibility improvements because every visitor benefits, including the roughly 8 percent of men and 0.5 percent of women with color vision deficiency.

When the audit also has to plan the room lighting around the screen, the Lighting calculator turns square footage and a recommended lux into total lumens so the ambient level stays inside the calibration envelope.

Contrast ratio calculator interface showing two hex color inputs, a live color preview, and the resulting contrast ratio alongside WCAG AA and AAA pass or fail badges
Contrast ratio calculator interface showing two hex color inputs, a live color preview, and the resulting contrast ratio alongside WCAG AA and AAA pass or fail badges

Frequently Asked Questions

Q: What is a good contrast ratio for accessibility?

A: Aim for at least 4.5:1 for body text and 3:1 for large text and essential UI components. The first number clears WCAG 2 AA for normal text; the second clears AA for large text.

Q: What is the WCAG AA contrast ratio for normal text?

A: WCAG 2 AA requires a contrast ratio of at least 4.5:1 between normal-size text and the background directly behind it. The same rule applies to link text and button labels.

Q: How is the WCAG contrast ratio calculated?

A: The ratio is (L1 + 0.05) / (L2 + 0.05), where L1 is the higher relative luminance and L2 is the lower. Each luminance is built from sRGB channels that have been linearized with the inverse sRGB companding curve.

Q: What contrast ratio do I need for large text?

A: Large text, which WCAG defines as 18 point regular or 14 point bold, only needs 3:1 under AA. For AAA, large text needs 4.5:1 instead of the 7:1 normal-text threshold.

Q: Why does relative luminance use sRGB gamma 2.4?

A: The 2.4 exponent models the non-linear way a typical display encodes brightness. Linearizing the sRGB channel with this exponent produces a luminance that matches how bright the color actually looks to the eye.

Q: What contrast ratio passes WCAG AAA?

A: AAA requires at least 7:1 for normal text and 4.5:1 for large text. AAA is the right target for long-form reading and content aimed at readers with low vision.