Contrast Ratio Calculator

This calculator works out the contrast ratio between any two colours, the WCAG measure of whether text or interface elements will be readable against their background. Enter a hex code for your foreground (text) colour and your background colour, or use the colour pickers or preset swatches, then watch the live preview update as you adjust each one. The tool applies the WCAG 2.1 relative luminance formula to both colours and returns the contrast ratio, the foreground and background relative luminance values, and an overall grade. It then checks that ratio against the official WCAG thresholds, showing a pass or fail for normal text, large text of 18pt and above, and user interface components, plus the stricter AAA level for normal and large text and a summary of the best level your combination achieves. A detailed breakdown shows the linearised RGB channels and luminance for each colour and the exact formula used to reach the final figure, so you can see every step of the working. Use it to check body text, headings, buttons and icons meet WCAG AA before you publish a design, or aim for AAA where higher accessibility matters. Colour inputs must be valid 6-digit hex codes, results apply to standard sRGB colour space, and the ratio alone does not account for colour blindness, so treat borderline results as a guide rather than a final sign-off.

Calculate.co.nz is proud to be partnered with Premium Homes, a recognised leader in eco-friendly, sustainable, and energy-efficient homebuilding. With a dedicated team and award-winning experience, they create homes that prioritise health, comfort, and long-term performance. Their founders, Andrew and Kelly, set out to raise the standard of residential construction in New Zealand by combining practical building expertise with a clear commitment to doing things better for homeowners.
Calculate.co.nz partner: Premium Homes
WCAG 2.1 formula  W3C Web Content Accessibility Guidelines 2.1 (ISO/IEC 40500:2012). WCAG 3.0 draft does not yet replace this standard.

1. Foreground Colour (Text)

Sample Text

2. Background Colour

Sample Text
Sample Text on This Background

Contrast Ratio Result

Contrast Ratio
21.00:1
Higher is better
Foreground Luminance
1.0000
Relative (0 to 1)
Background Luminance
0.0000
Relative (0 to 1)
Overall Grade
AAA
Best WCAG level met

WCAG 2.1 Accessibility Check

AA
Normal text
Minimum 4.5:1
Pass
AA
Large text (18pt+)
Minimum 3:1
Pass
AA
UI components
Minimum 3:1
Pass
AAA
Normal text
Minimum 7:1
Pass
AAA
Large text (18pt+)
Minimum 4.5:1
Pass
Summary
Overall rating
Best level achieved
AAA All

Luminance Breakdown

Foreground colour#FFFFFF
Foreground RGBrgb(255, 255, 255)
Foreground linearised R1.0000
Foreground linearised G1.0000
Foreground linearised B1.0000
Foreground luminance (L1)1.0000

Calculation Steps

Background colour#000000
Background RGBrgb(0, 0, 0)
Background luminance (L2)0.0000
Lighter luminance (L1)1.0000
Darker luminance (L2)0.0000
Contrast ratio formula(1.0000 + 0.05) / (0.0000 + 0.05) = 21.00
Result: Enter two colours above to check their contrast ratio.

What Is Contrast Ratio?

Contrast ratio is a measure of the visual difference in luminance between two colours, typically a foreground (text) and background colour. It is expressed as a ratio such as 4.5:1 or 21:1. A ratio of 1:1 means the colours are identical with no contrast. A ratio of 21:1 is the maximum possible contrast, achieved between pure white and pure black.

High contrast between text and background is essential for readability, particularly for people with low vision, colour blindness, or who read in challenging lighting conditions. The Web Content Accessibility Guidelines (WCAG) published by the W3C set minimum contrast requirements for digital content. New Zealand's government web accessibility standard (Web Accessibility Standard 1.1) requires conformance with WCAG 2.1 Level AA.

The WCAG Relative Luminance Formula

WCAG 2.1 defines relative luminance as the normalised luminance of a colour, ranging from 0 (pure black) to 1 (pure white). The calculation steps are:

  1. Divide each RGB channel value (0 to 255) by 255 to get a value between 0 and 1.
  2. Linearise each channel: if the channel value is 0.04045 or below, divide by 12.92. If above 0.04045, apply: ((value + 0.055) / 1.055) ^ 2.4
  3. Calculate relative luminance: L = 0.2126 x Rlin + 0.7152 x Glin + 0.0722 x Blin
  4. Determine contrast ratio: CR = (Llighter + 0.05) / (Ldarker + 0.05)

The 0.05 offset in the contrast ratio formula represents the luminance of the display surface, accounting for the fact that even a "black" screen has some minimum light output.

WCAG Accessibility Requirements

Content TypeWCAG AA (minimum)WCAG AAA (enhanced)
Normal body text (below 18pt or 14pt bold)4.5:17:1
Large text (18pt or larger, or 14pt bold or larger)3:14.5:1
UI components and graphical objects3:1Not defined
Decorative text or logosNo requirementNo requirement
Disabled text or componentsNo requirementNo requirement

Note: 18pt is approximately 24px at standard screen resolution. 14pt bold is approximately 18.67px bold.

Worked Example

Using white (#ffffff) as the foreground (text colour) and black (#000000) as the background:

This 21:1 ratio is the maximum achievable and represents the default output of this calculator. Most designs aim for at least 4.5:1 for body text, which allows more colour freedom while maintaining accessibility.

Practical Tips for Accessible Colour Design

Related Calculators

Sources and method: W3C Web Content Accessibility Guidelines (WCAG) 2.1, Success Criterion 1.4.3 (Contrast Minimum) and 1.4.6 (Contrast Enhanced) (w3.org/TR/WCAG21). W3C WCAG 2.x relative luminance definition and contrast ratio formula (w3.org/TR/WCAG21/#dfn-relative-luminance). New Zealand Government Web Accessibility Standard 1.1 (digital.govt.nz).

This calculator implements the WCAG 2.1 relative luminance and contrast ratio formula exactly as defined by the W3C. Results apply to standard sRGB colour space. Colour inputs must be valid 6-digit hex codes. The calculator does not account for colour blindness, font rendering differences, or non-standard display profiles.