The Word Wide Web Consortium (W3C) has a formula for the contrast ratio of any two arbitrary colors, which they use to set minimum standards for text legibility: http://www.w3.org/TR/WCAG20-TECHS/G18.html

Step 1 of the process is relatively straight-forward - it uses a well known conversion from sRGB to XYZ and keeps the Y component for the next step. Step 2 is the same for the second color.

My question comes in step 3, where the ratio is determined as (L1 + 0.05) / (L2 + 0.05) with L1 and L2 being the luminances of the lighter and darker colors from steps 1 and 2. Where does the magic constant 0.05 come from? It's obvious that some constant offset is needed, otherwise pure black would have infinite contrast against every other color. But how is it derived?

Also, does this contrast ratio reasonably describe how easy it is to discern text against a background? Or is there a different formula that would be better?

I ask because it seems to favor black over white - where I see better results with white text, the formula suggests black is better.

https://www.w3.org/WAI/ER/tools/ gives a list of accessibility evaluation tools which includes a contrast checker and the WAVE tool by WebAIM checks the contrast ratios along with other accessibility features.

I'd like a clearer understanding on how this is calculated.

  • 1
    $\begingroup$ I came across this today which at least gives sources for the formulas: w3.org/TR/UNDERSTANDING-WCAG20/…. I haven't yet poked through the links to study the rationale. $\endgroup$ Apr 21, 2016 at 20:24
  • $\begingroup$ Great question, @Mark! Unfortunate there still has been no answer to this. Thank you for the update, and maybe another 5 years later you have learned more? :) $\endgroup$
    – Steven Jeuris
    Sep 27, 2021 at 9:16
  • $\begingroup$ @StevenJeuris thanks. I already had a better equation when I asked the question, so I wasn't too motivated to dig to the bottom of it. I also wonder if there was a better forum to ask on. $\endgroup$ Sep 27, 2021 at 15:17
  • 1
    $\begingroup$ ux.stackexchange.com is an alternative, but cross-posting is not appreciated. If you want I can migrate it there, even though it is fully on topic here. I'll try adding a bounty first to see whether we can attract a bit of attention. $\endgroup$
    – Steven Jeuris
    Sep 27, 2021 at 15:30

1 Answer 1


The W3C link provided by Mark in a comment on "Understanding WCAG 2.0" provides the source for the contrast ratio formula under the "Notes on formula" section.

The formula (L1/L2) for contrast is based on [ISO-9241-3] and [ANSI-HFES-100-1988] standards.

The ANSI/HFS 100-1988 standard calls for the contribution from ambient light to be included in the calculation of L1 and L2. The .05 value used is based on Typical Viewing Flare from [IEC-4WD] and the [sRGB] paper by M. Stokes et al.

Although [IEC-4WD] is a paywalled ISO standard, the free [sRGB] reference provides some additional information:

Typical Viewing flare is specified to be 5.0% of the maximum white-luminance level.

Although I have found no confirmation of your observation that this formula "seems to favor black [text] over white", I speculate that black text may be preferred by the formula since it accounts for ambient illumination and flare.

The reason that a viewing gamma of 1.125 is used instead of 1.0 is to compensate for the viewing environment conditions, including ambient illumination and flare.

It thus favors brighter environments, in which black on bright backgrounds are likely easier to perceive than white on darker surfaces (citation needed for this, though).


IEC-4WD: IEC/4WD 61966-2-1: Colour Measurement and Management in Multimedia Systems and Equipment - Part 2.1: Default Colour Space - sRGB. May 5, 1998.

sRGB "A Standard Default Color Space for the Internet - sRGB," M. Stokes, M. Anderson, S. Chandrasekar, R. Motta, eds., Version 1.10, November 5, 1996. A copy of this paper is available at http://www.w3.org/Graphics/Color/sRGB.html.

  • 1
    $\begingroup$ This is a great explanation for where the magic constant .05 came from, thank you! Unfortunately it doesn't answer the real question I had, which was why the formula correlates so poorly with my own real world experience. $\endgroup$ Sep 28, 2021 at 14:33
  • $\begingroup$ @MarkRansom You are right, I overlooked that part of the question, but I understood it as a sub question. :) If that was the "real" question, maybe additional emphasis should have been on that, e.g., making it the question title. ;p Regardless, if I have time I'll see whether I can dig deeper and update the answer! I will keep you posted. For anyone else, this means there is room for improvement and the bounty is clearly still open. ;) $\endgroup$
    – Steven Jeuris
    Sep 28, 2021 at 14:37
  • 1
    $\begingroup$ And you're right too, my question wasn't clear enough. It doesn't help that someone else made a recent edit and deemphasized my concluding line. $\endgroup$ Sep 28, 2021 at 14:46
  • $\begingroup$ @MarkRansom I added some speculation which may explain your observation that the formula seems to favor black text on white, but could not immediately find citations to back it up. $\endgroup$
    – Steven Jeuris
    Oct 4, 2021 at 8:59

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.