Techniques for WCAG 2.0

On this page:

-

# G17: Ensuring that a contrast ratio of at least 7:1 exists between text (and images of text) and background behind the text

## Applicability

Any technology that produces visual output.

This technique relates to:

- Success Criterion 1.4.6 (Contrast (Enhanced))
  - How to Meet 1.4.6 (Contrast (Enhanced))
  - Understanding Success Criterion 1.4.6 (Contrast (Enhanced))

## Description

The objective of this technique is to make sure that users can read text that is presented over a background. This technique goes beyond the 4.5:1 contrast technique to provide a higher level of contrast to make it easier for people with low vision to read.

If the background is a solid color (or all black or all white) then the contrast ratio of the text can be maintained by making sure that each of the text letters have a 7:1 contrast ratio with the background.

If the background or the letters vary in relative luminance (or are patterned), then the background around the letters can be chosen or shaded so that the letters maintain a 7:1contrast ratio with the background behind them even if they do not have that contrast ratio with the entire background.

The contrast ratio can sometimes be maintained by changing the relative luminance of the letters as the relative luminance of the background changes across the page.

Another method is to provide a halo around the text that provides the necessary contrast ratio if the background image or color would not normally be sufficiently different in relative luminance.

## Examples

- A black background is chosen so that light colored letters that match the company's logo can be used.

- Text is placed over a picture of the college campus. Since a wide variety of colors and darknesses appear in the picture the area behind the text is fogged white so that the picture is very faint and the maximum darkness is still light enough to maintain a 7:1 contrast ratio with the black text written over the picture.

## Resources

Resources are for information purposes only, no endorsement implied.

- Contrast Analyser – Application

- Contrast Ratio Analyser - online service

- Colour Contrast Analyser - Firefox Extension

- Color Contrast Samples

- Atypical colour response

- Colors On the Web Color Contrast Analyzer

- Tool to convert images based on color loss so that contrast is restored as luminance contrast when there was only color contrast (that was lost due to color deficiency)

- List of color contrast tools

## Related Techniques

- G148: Not specifying background color, not specifying text color, and not using technology features that change those defaults
- G174: Providing a control with a sufficient contrast ratio that allows users to switch to a presentation that uses sufficient contrast

## Tests

### Procedure

1. Measure the relative luminance of each letter (unless they are all uniform) using the formula:

   - L = 0.2126 * R + 0.7152 * G + 0.0722 * B where R, G and B are defined as:

     - if RsRGB <= 0.03928 then R = RsRGB/12.92 else R = ((RsRGB+0.055)/1.055) ^ 2.4

     - if GsRGB <= 0.03928 then G = GsRGB/12.92 else G = ((GsRGB+0.055)/1.055) ^ 2.4

     - if BsRGB <= 0.03928 then B = BsRGB/12.92 else B = ((BsRGB+0.055)/1.055) ^ 2.4

     and RsRGB, GsRGB, and BsRGB are defined as:

     - RsRGB = R8bit/255

     - GsRGB = G8bit/255

     - BsRGB = B8bit/255

     The "^" character is the exponentiation operator.

   Note: For aliased letters, use the relative luminance value found two pixels in from the edge of the letter.

2. Measure the relative luminance of the background pixels immediately next to the letter using same formula.

3. Calculate the contrast ratio using the following formula.

   - (L1 + 0.05) / (L2 + 0.05), where

     - L1 is the relative luminance of the lighter of the foreground or background colors, and

     - L2 is the relative luminance of the darker of the foreground or background colors.

4. Check that the contrast ratio is equal to or greater than 7:1

### Expected Results

- #4 is true

- Top
- Contents
- Intro
- Previous: Technique G15
- Next: Technique G18