4

To calculate contrast ratio the following formula is used (source):

(L1 + 0.05) / (L2 + 0.05)

where:

L1 is the relative luminance of the lighter of the colors, and

L2 is the relative luminance of the darker of the colors.

My question is, what is the number 0.05 in this formula?

3 Answers 3

4

The Gamma correction and RGB constants are derived from the Standard Default Color Space for the Internet (sRGB), and the 0.05 offset is included to compensate for contrast ratios that occur when a value is at or near zero, and for ambient light effects. - http://juicystudio.com/article/luminositycontrastratioalgorithm.php

1
2

Well, without it, if L2 is darkest black, which has a relative luminance of 0, the ratio would be undefined since you can't divide by zero.

So they decided to add a small factor to make sure the ratio is always defined. The consequence of using 0.05 is that the maximum ratio is 1.05 : 0.05 = 21 : 1.

Note 1: Contrast ratios can range from 1 to 21 (commonly written 1:1 to 21:1).

Why they chose exactly this number, I have no idea.

2

The 0.05 addition was intended to represent the flare on the face of the monitor from ambient illumination that was typical of CRT type displays, this flare value is recited in Annex D of the sRGB standard for Typical Viewing Conditions

I discuss the history in this GitHub thread

Unfortunately, adding the flare value to both sides of the formula doesn't actually correct the problem with using a simple contrast ratio in terms of its lack of perceptual uniformity, so that algorithm really only works when the background is very light or white.

Ratios are not the best way to model human perception of text contrast at suprathreshold levels on a self illuminated display. For an example of a contrast method that uses a more comprehensive model of contrast perception, see apcacontrast.com (disclosure, I am the creator of the APCA algorithm).

8
  • Some room for improvement in contrast (Firefox, Android 12 in dark mode) Jul 18, 2023 at 23:06
  • Hi @LukeSawczak YIKES that purple link text is an APCA fail regardless of text size. At Lc -24 it's below the minimum for text cut off. Where did you see that and how is that related to Firefox?
    – Myndex
    Jul 19, 2023 at 2:17
  • It's a screenshot from your site, and I quote Firefox only to help you track down the platform on which it displays like that. I can give more detail if it's helpful. Jul 19, 2023 at 2:35
  • 2
    Ahh, guess what. I didn't look carefully enough. It is an extension. Dark Reader. I assumed that none of my extensions from desktop were here on mobile, but it turns out that one alone bridges the gap. Sorry! Jul 22, 2023 at 13:41
  • 2
    Hi @LukeSawczak whew! thank you for getting back to me, I suspected it might've been an extension... I like dark reader actually, it's pretty cool, but if it's not set up for a particular site sometimes it doesn't get it right.... Thanks for clarifying!
    – Myndex
    Jul 23, 2023 at 8:22

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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