---
name: measure-text-contrast
description: "Calculate the contrast ratio between text and its background with the WCAG formula and decide pass or fail against the 4.5:1 or 3:1 threshold for its size and weight. Use when someone asks whether text colours, a button label or text over an image meets WCAG AA colour contrast."
license: CC-BY-4.0
metadata:
  author: Raq.com
  version: "2026-11-22"
  homepage: https://skills.raq.com/skills/measure-text-contrast
---

# Measure text contrast against its background

Calculate text contrast with the WCAG relative luminance formula and apply the size-specific threshold before rounding the result.

## When to use this skill

- Someone gives hex or RGB colours for text and background and asks whether they pass WCAG AA.
- A design review needs to know whether grey body text, link colours, placeholder text or button labels are readable enough.
- Text sits over a photo, gradient or semi-transparent overlay and the team wants to know whether it passes.

## When not to use it

- Contrast of icons, focus indicators, chart lines or input borders. Those fall under WCAG 1.4.11 Non-text Contrast (3:1 against adjacent colours), a different check.
- Enhanced contrast at AAA (WCAG 1.4.6: 7:1, or 4.5:1 for large text) unless the person asks for that level.
- Judging whether a particular person with low vision can read the text. The ratio is a minimum; some people also need larger text or their own colour settings.

## What you need

- Opaque sRGB foreground and background values, or enough compositing evidence to establish the effective colours.
- Text size in CSS pixels, boldness and whether it qualifies for a stated exception such as inactive controls.

## Ask before you start

If any of these are missing or unclear, ask before doing the work.

- What are the exact text and background colours as rendered, including any opacity, overlay or image behind the text? Design-file colours and rendered colours can differ.
- What size and weight is the text, in CSS pixels or points? The threshold depends on both.
- Which states should be checked: default, hover, focus, visited, error or disabled? Each colour pair is a separate check.
- Is the target WCAG 2.2 AA, or a stricter level or local standard?

## Method

1. Establish the effective colours behind the letters as rendered. Composite any transparency over the actual background before measuring. On photos, gradients or overlays, find the lowest-contrast area behind any letter: one failing region is a failure, and one passing sample cannot clear an unknown background.
2. Convert each 8-bit channel to 0-1 by dividing by 255. Linearise with c/12.92 when c is at most 0.04045, otherwise ((c+0.055)/1.055)^2.4. Relative luminance L = 0.2126R + 0.7152G + 0.0722B. Older copies of the formula show 0.03928; W3C says the change makes no practical difference.
3. Compute the contrast ratio (L1 + 0.05)/(L2 + 0.05), where L1 is the lighter colour. Ratios run from 1 to 21.
4. Choose the WCAG 2.2 success criterion 1.4.3 (AA) threshold: 4.5:1 for ordinary text and 3:1 for large-scale text, which is at least 18 point (24 CSS pixels) or 14 point bold (1pt = 1.333px, so about 18.66 CSS pixels). Use the size as delivered, before any zoom by the user.
5. Compare the unrounded ratio with the threshold: 4.499 does not meet 4.5. Round to two decimals only for display.
6. Apply the exceptions only where they genuinely fit: text in an inactive control, pure decoration, text nobody can see, text that is part of a picture with plenty of other visual content, and text in a logo have no requirement. Mark these exempt rather than calculating a pass.
7. Report each state and colour pair separately. For a failure, suggest a darker or lighter replacement colour and give its recalculated ratio.

## Checks before you deliver

- Using a perceived brightness average or comparing rounded ratios gives incorrect decisions near the threshold.
- The reduced large-text threshold depends on both size and weight. Inactive controls are a separate exception.
- Measuring a semi-transparent text colour as if it were opaque overstates the contrast. Blend it with the real background first.
- A text outline counts differently by width. W3C treats a narrow border as part of the letter and a wide halo that fills in the letters as the background.
- Checking only the default state misses hover, focus, visited and error colours, which are often lighter.

## How to present the result

Start with the result for each item: pass or fail, the ratio to two decimals and the threshold used. Then give a table with each item's colours, size and weight, state, ratio, threshold and result. For each failure, suggest a replacement colour with its recalculated ratio, and list any backgrounds that still need sampling.

## Worked example

**Request:** Check AA contrast for ordinary active text on solid white.

**Supplied material:**

```text
T1 foreground #777777, background #FFFFFF, 16px regular
T2 foreground #777777, background #FFFFFF, 24px regular
```

**Answer:** The 16px text fails AA at 4.48:1 against white. Darken the text and retest for at least 4.5:1 before rounding. The same colour pair passes for the 24px heading, which needs 3:1.

## Structured output for tests

For an ordinary job, answer in the format above and point back to the supplied evidence. Use this structure only for the test cases published with this skill, or when someone asks for structured JSON.

Return checks in supplied order as {id,ratio,threshold,result}. ratio is numeric rounded to two decimals and threshold is 3 or 4.5. result is pass or fail. For exempt inactive text or undetermined backgrounds return null for ratio and threshold and result exempt or unknown respectively.

## Sources

- [W3C Understanding Contrast (Minimum)](https://www.w3.org/WAI/WCAG22/Understanding/contrast-minimum.html): Explains WCAG 2.2 success criterion 1.4.3 (Level AA): 4.5:1 for text, 3:1 for large-scale text, and the exceptions for inactive components, decoration, invisible text, pictures and logotypes. It says computed values must not be rounded (4.499:1 does not meet 4.5:1) and gives 1pt = 1.333px.
- [WCAG 2.2 definition of relative luminance](https://www.w3.org/TR/WCAG22/#dfn-relative-luminance): The normative sRGB formula: the 0.04045 linearisation threshold, the 0.2126, 0.7152 and 0.0722 coefficients, and the note that the earlier 0.03928 value has no practical effect. The same glossary defines the contrast ratio and large-scale text as at least 18 point or 14 point bold.
- [W3C technique G18 for text contrast](https://www.w3.org/WAI/WCAG22/Techniques/general/G18): G18 measures each letter against the background immediately behind it and describes a halo as a way to keep contrast over varied backgrounds. The skill uses it for text over photos and gradients.

Test cases and an answer checker for this skill: https://skills.raq.com/skills/measure-text-contrast
