XML technologies / CSS / CSS Cookbook / Design with CSS / Checking for sufficient color contrast
(Excerpt from “CSS Kochbuch” by Christopher Schmitt)
Problem
Ensure that the contrast between two colors is sufficiently high.
Solution
Use the Luminosity Contrast Ratio Analyser, a tool for calculating the luminosity contrast ratio.
Enter two hexadecimal color values in the form, then click “Calculate Luminosity Contrast Ratio,” as shown in the next figure.
Figure: Entering values to check the luminosity contrast ratio.
Along with an example combining the two colors as background and text, the tool displays their luminosity contrast ratio. A higher “contrast ratio” means greater contrast. Three levels express the result more simply: 1 = insufficient, 2 = adequate, 3 = very good. Our example reaches level 3, indicating a very good luminosity contrast ratio (see the following figure).
Figure: Luminosity contrast ratio test results.
Discussion
The W3C’s Web Content Accessibility Guidelines (Web Content Accesibility Guidelines) ask designers to provide enough contrast between foreground and background for the foreground to be easily perceived.
If text is too close to its background in hue or brightness, it quickly becomes unreadable. For easy reading, the colors must be separated in the spectrum or differ sufficiently in brightness within the same hue.
Yellow text on a black background is an example of high contrast, like the Batman logo from Tim Burton’s Batman films of the 1990s.
Reaching level two requires a luminosity contrast ratio of at least 5:1: one color must be at least five times brighter or darker than the other.
Level three requires a luminosity contrast ratio of at least 10:1.
See also
The JuicyStudio website’s explanation of the algorithm used to calculate the luminosity contrast ratio.
Copyright of the German edition © 2007 by O’Reilly Verlag GmbH & Co. KG
You may print the online version for your private use.
Otherwise, this chapter from “CSS Kochbuch” is subject to the same conditions as the bound edition: the work, including all its parts, is protected by copyright. All rights reserved, including reproduction, translation, microfilming, and storage and processing in electronic systems.
O’Reilly Verlag GmbH & Co. KG, Balthasarstr. 81, 50670 Köln