iTranslated by AI
[WCAG 2.2] Learning How to Calculate Contrast Ratios
Introduction
One of the factors that greatly affects text readability is the contrast between the text and its background. While I have used various tools to check contrast ratios in the past, I didn't understand the specific calculation method.
Therefore, in this article, I would like to introduce what I have learned about calculating contrast ratios, referring to the Web Content Accessibility Guidelines (WCAG) 2.2.
What is Contrast in Web Accessibility?
In general, the word "contrast" means comparison or opposition. Specifically, in the context of web accessibility, the word contrast often refers to the contrast (comparison) between text and its background.
Many different visual impairments can substantially impact contrast sensitivity, requiring more light-dark contrast, regardless of color (hue). For people who are not able to distinguish certain shades of color (often referred to as color blindness) hue and saturation have minimal or no effect on legibility as assessed by reading performance. Further, the inability to distinguish certain shades of color does not negatively affect light-dark contrast perception.
Reference: Understanding Success Criterion 1.4.3: Contrast (Minimum) | WAI | W3C
According to the above, many different visual impairments can significantly impact sensitivity to light-dark contrast, regardless of color (hue). For people who cannot distinguish between certain colors (often referred to as color blindness), hue and saturation have little to no effect on readability as assessed by reading performance. Furthermore, the inability to distinguish certain colors does not negatively affect the perception of light-dark contrast.
For these reasons, WCAG 2.2 recommendations calculate contrast in a way that does not use color (hue) as the primary factor.
How to Calculate Contrast Ratio
The formula for the contrast ratio is described in WCAG 2.2. The formula is as follows:
Here,
How to Calculate Relative Luminance
The term relative luminance, which we haven't seen before, appeared above. This is also defined in WCAG 2.2.
the relative brightness of any point in a colorspace, normalized to 0 for darkest black and 1 for lightest white
Relative luminance is the relative brightness of any point in a colorspace, normalized to 0 for the darkest black and 1 for the lightest white.
The method for calculating relative luminance (
In this case,
- If the value is
or less:0.04045 {\text{value}} / {12.92} - If the value is greater than
:0.04045 ((\text{value} + 0.055) / {1.055}) ^ {2.4}
This can be expressed as follows:
Additionally,
By calculating the above, you can obtain the relative luminance (
Calculating the Contrast Ratio of White and Black
As an example, let's calculate the contrast ratio of #FFFFFF (white) and #000000 (black).
Calculating the Relative Luminance of White
First, let's find the relative luminance of white. The 8-bit RGB value for white is
Therefore,
Since each value is greater than
Finally, calculate the relative luminance:
Calculating the Relative Luminance of Black
Next, let's find the relative luminance of black. The 8-bit RGB value for black is
Therefore,
Since each value is less than
Finally, calculate the relative luminance:
Calculating the Contrast Ratio
Finally, calculate the contrast ratio:
Therefore, the contrast ratio between white and black is 21:1.
This is the case with the highest possible contrast ratio, which is intuitively easy to understand.
Success Criteria for Contrast in Text
In WCAG 2.2, there are success criteria for text contrast: "Contrast (Minimum)" and "Contrast (Enhanced)".
Contrast (Minimum)
Success Criterion 1.4.3: Contrast (Minimum) contains the following description. This is a Level AA success criterion.
The visual presentation of text and images of text has a contrast ratio of at least 4.5:1
According to the above, the contrast ratio of text and images of text must be at least 4.5:1.
However, the following cases are exceptions:
-
Large Text
If the font size is at least 18pt (24px), or at least 14pt (18.5px) and bold, a contrast ratio of at least 3:1 is required. -
Incidental
There is no contrast requirement for inactive user interface components, pure decoration, text that is not visible to anyone, etc. -
Logotypes
There is no contrast requirement for text that is part of a logo or brand name.
Contrast (Enhanced)
Success Criterion 1.4.6: Contrast (Enhanced) contains the following description. This is a Level AAA success criterion.
The visual presentation of text and images of text has a contrast ratio of at least 7:1
According to the above, the contrast ratio of text and images of text must be at least 7:1.
However, the following cases are exceptions:
-
Large Text
If the font size is at least 18pt (24px), or at least 14pt (18.5px) and bold, a contrast ratio of at least 4.5:1 is required. -
Incidental
There is no contrast requirement for inactive user interface components, pure decoration, text that is not visible to anyone, etc. -
Logotypes
There is no contrast requirement for text that is part of a logo or brand name.
Summary
The two success criteria mentioned above can be summarized as follows:
| Type of Content | Minimum (Level AA) | Enhanced (Level AAA) |
|---|---|---|
| Normal Text | 4.5:1 or higher | 7:1 or higher |
| Large Text | 3:1 or higher | 4.5:1 or higher |
| Incidental | No requirement | No requirement |
| Logotype | No requirement | No requirement |
Conclusion
In this article, we learned how to calculate contrast ratios. By learning the specific calculation method, I feel that my understanding of contrast, which was previously vague, has deepened slightly. While meeting WCAG success criteria may not be everything, I believe it is very important knowledge to have. I hope the content of this article is helpful.
References
Discussion