Colouring-in Team

Essays / tags / legibility


Understanding contrast

In my last post I talked about what it means to say that text is legible. If you haven't read it, you might want to take a look before you dive into this one, as some of the maths follows on.

It's pretty obvious that contrast can and does have a significant impact on legibility, and therefore also readability, and not enough of it can make for an unpleasant user experience. To counter this problem there are strict guidelines set out by W3C. If you work in web-based media you'll be familiar with the Web Content Accessibility Guidelines (WCAG), which define minimum contrast values for text in both AA and AAA accessibility standards. WCAG 2.0 level AA requires a minimum contrast ratio of 4.5:1 for normal text and 3:1 for large text. Level AAA requires a contrast ratio of at least 7:1 for normal text and 4.5:1 for large text. And the guidelines also state that once contrast reaches 7:1, legibility is unaffected beyond this point. And if that all seems a bit impenetrable, there are many online contrast checking tools available that allow you to test your proposed text foreground and background colours to see if they meet the guidelines.

What is contrast?

In simple terms, contrast in vision is the ability of the eye to distinguish between differing colour and brightness. The values listed above are the ratio of the 'luminance' between the foreground and background colours (though not necessarily in that order). You can think of luminance in this context as a measure of the intensity of light as perceived by the human eye. Some wavelengths (i.e. colours) of light have more luminance than others, peaking in the green-yellow part of the spectrum.

The process by which contrast ratios are calculated probably isn't for the mathematically faint-hearted, but I'll set it out anyway. Feel free to skip to the next heading if it all looks like Greek to you. It probably is.

The first step is to work out the relative luminance of the foreground and background colours in question. To do that we use these formulas:

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

...where...

RsRGB = R8bit / 255

GsRGB = G8bit / 255

BsRGB = B8bit / 255

You can think of the SRGB values as proportions of red, green and blue. Thus, if your text colour was specified as #800000, that's a red value of 80 in hex, or 128 as a decimal, so the SRGB value for red would be 128/255 = 0.5.

We can now calculate luminance by combining the R, G and B values above in the following way:

L = (0.2126 x R) + (0.7152 x G) + (0.0722 x B)

Note that to acquire a luminance value we are essentially adding up the red, green and blue values, adjusted by constants in accordance with how much of an impact those wavelengths of light have on luminance. Thus the green value has a far bigger impact on the final luminance value than the blue value.

Finally, having calculated L for both the foreground (text) colour and the background colour, we can work out the contrast ratio between the two quite simply, as follows:

Contrast ratio = (L1 + 0.05) / (L2 + 0.05)

Where L1 is the most luminous and L2 the least luminous of the two colours.

OK, so that's the scary maths-bit over...

So why am I interested in this? Well, at present if we designers want our websites to be AA or AAA compliant, they must meet with the contrast guidelines described above. But in real life, of course things are rarely as simple as a binary rule: "THIS text is legible, THAT text isn't..."

Text on the web that is illegible or at least hard-to-read due to the choice of colours is nothing new. Katie Sherwin, writing on the Nielsen-Norman Group blog, has some interesting things to say about the use of low-contrast text on the web.

What I'm suggesting here is that it is possible to have hard-to-read text that meets the WCAG rules, and easy-to-read text that doesn't. For example...

As far as I can tell, this text passes the AA level guidelines, with a contrast ratio of about 4.5:1.... The question is, is it easy to read? I suspect that most people would find this paragraph harder to read than the next one. I'm deliberately droning on and on here, just to make sure there is a nice long block of text to really ram home the point I'm trying to make. Fortunately for you, the next box just says...

bicycle.

So, in case it wasn't already clear, the top box should pass AA guidelines, but the text in the bottom box fails both AA and AAA.

Now, to be clear, this isn't due to lack of care on the part of the clever people who make up the WCAG. In fact the guidelines go to some lengths to explain the choice of contrast-ratios used as cut-off points, and they are clearly the result of considerable thought and research. My point is really that, as soon as you introduce any sort of binary rule into design, it immediately creates space for applications of that rule that seem outside of what was intended, such as the text above.

Now, designers clearly can't user-test each piece of text we want to use to see if it the contrast works well enough, and a hard-and-fast rule is a pretty safe alternative. But what if, instead, we try to look at the effect contrast has on legibility, and apply it on a case-by-case basis to mathematically assess how legible and how readable a piece of text will be, across devices. Can we construct a formula that would warn you that the red box above might be hard to read, but reassure you that the text below it is likely to be just fine?

Modelling contrast

We know that contrast effects legibility. Therefore it is logical to suggest that, in most cases, a reduction in contrast can be countered with an increase in text size. Consider the text you are reading right now:

If I suddenly make it slightly lighter, it becomes harder to read, right?

But if also make it bigger, it's not so much of a problem.

Now imagine a graph where we plot the size a character needs to be to maintain it's level of legibility against its contrast with its background. Thinking about how this model might look, we can see we already have two known points on the graph.

Firstly, according to WCAG, once contrast reaches 1:7 there is no further improvement in legibility. We express 1:7 as 1 divided by 7, or 0.143, so this gives us the start of our graph. To the left of this point (i.e. where contrast is better) it should level out.

Secondly, we might reasonably say that if the size of text has to increase each time contrast decreases, then the other end of the graph must tend towards infinity. To put it another way, once contrast has a ratio of 1:1 (for instance white on white or black on black), the text would have to be infinitely large i.e. it can never be legible at that contrast ratio.

In between I will assume (for want of information to the contrary) that the relationship is a smooth curve. Thinking about these few characteristics, we end up with a graph that looks a bit like this:

The next logical step is to try and find a mathematical function that will produce a curve that looks like this, so that we can predict the necessary change in text height for any given contrast ratio. To me, that looks a little like a 1 / 1-x function, though if anyone reading is a proper mathematician (or knows one), I would welcome any alternative suggestions. The best-guess function I have at present is...

y=max(1, 6/7(1-x))

Putting it into practice

Having come up with a function that might model the effects of contrast on legibility, it seems sensible to try it out. I have created a sort of legibility testing tool to do this. Feel free to try it out and have a play, although be aware that it is all rather Beta, and probably as likely to break as to work. The font detection relies on Flash, and also won't work if you're using any sort of 'private browsing' mode. It also takes a few seconds to work, so have patience.

Stupidly, I borrowed the font-detection AND the nifty size-calculation scripts from somewhere, and can't remember where. If they're yours please let me know so I can give credit where it's due!

What is it all for?

This tool is designed to combine all of the legibility-related calculations from this blog post and the previous one, and allow a designer to choose any locally-installed font, specify the size, colours, and intended device on which it will be displayed, and see just how legible it might be.

The point of all this is twofold:

  1. To enable designers to make better decisions about typography, for a more readable web experience.
  2. To free designers from the constraints of hard-and-fast contrast rules, so that where branding or aesthetics require type to appear outside of the suggested cut-off points, a judgement call can be made with confidence.

Next steps

The plan is to test the theory. I've written some testing software that should enable me to test real eyeballs under controlled conditions, and see if the relationship between text size and contrast really does look like this. It may be a little while before a large-scale test can happen (though with help from my awesome colleagues at Zone it shouldn't be too long, I hope), but early signs are good. Here is a chart of results from testing myself and a couple of others in not-very-controlled conditions...

Relative Text Height vs Contrast Ratio

If you found this useful or interesting, or if you know anything about this topic and you don't mind sharing, please add a comment below. Thanks for reading.

References and Links

WebAIM: Color Contrast Checker

Contrast Rebellion

Contrast Sensitivity Testing

Wikipedia entry: Luminosity function

Conference Paper: Human Computer Interaction, Legibility and Contrast



Categories: Design, UX, Web design

Tags: accessibility, contrast, legibility, readability, ux

Share:

Understanding legibility

What minimum text size should be used on the web?

If you work in digital design you probably have some sort of answer in mind. Maybe you have a preferred size for readability, and a lower limit you won't drop below. Perhaps you remember the WCAG guidelines. Whatever your answer, the next question is probably more tricky: why?

With the range of screen sizes and resolutions currently available, not to mention the variation in the way we use devices, it is becoming increasingly hard to know exactly what is a sensible minimum, or a comfortable size for reading. In this post I will attempt to explain what 'legibility' means, technically, and how this can help you make better decisions about text size.

“Typography has one plain duty before it and that is to convey information in writing. No argument or consideration can absolve typography from this duty. A printed work which cannot be read becomes a product without a purpose.” - Emil Ruder

How good is your eyesight?

'Snellen chart' by Jeff Dahl - Own work by uploader, Based on the public domain document: [1]. Licensed under CC BY-SA 3.0 via Wikimedia Commons

One way of describing the sharpness of eyesight is with the 'Snelllen scale'. As I understand it, this is actually somewhat old-fashioned these days, but for the purposes of this explanation it is ideal. You're probably already familiar with this measurement: normal eyesight is described as "twenty-twenty" (20/20).

So what does that mean? On the right is a Snellen Chart, a method of measuring visual acuity developed in 1862 by Dutch ophthalmologist Herman Snellen. A descendant of this chart is still used today. The smallest line of characters that a person with so-called 'normal' vision can read at a distance of 20 feet is the 20/20 line. If a person is said to have 20/40 vision, they can just about read at 20 feet what can normally be read at 40 feet. And likewise if you were lucky enough to have 20/10 vision it would mean you could read at 20 feet what others could only read at 10 feet.

Technically, whether or not something is legible is all down to the angle the character being viewed makes with the eye. That is, it is the perceived size that is crucial, not the physical size. Small-print on the back of a form held a few inches from your face may be easier to read than giant words on a billboard a few hundred metres away. You can visualise it like this:

It is a simple matter of either trigonometry or common-sense to demonstrate that the relationship between the distance and the character-height is linear, meaning that you can maintain the same angle at twice the distance by doubling the character-height.

It's all about angles

Going back to that definition of normal eyesight, the angle those characters on the 20/20 line make with the eye at a distance of 20 feet is 5 minutes of arc, a minute of arc being one sixtieth of a degree.

The characters that form the chart are actually very interesting. They are known as 'optotypes', and they have some important characteristics. Firstly, the width of the lines is the same as the the width of the spaces. Secondly, the width and height of each character is five times that line-width.

What this means in practice is that when a person is able to discern an optotype that makes an angle of 5 minutes of arc with their eye, that in turn means they can "resolve a spatial pattern separated by a visual angle of one minute of arc". If that sounds confusing, look at the capital E. To read it you must be able to differentiate three horizontal bars and two spaces: five elements in total.

Note that although these definitions reference distance vision, the actual measurement of visual performance is not related to a particular prescription for lenses. Factors beyond myopia or hyperopia can affect a person's ability to resolve a sharp image, including astigmatism, problems with the shape of the eyeball or cornea, and even neural problems. It is, however, a measurement only concerned with central vision, and not peripheral vision.

Some vision trivia...

  • About 35% of adults have natural 20/20 vision, rising to about 75% with the use of corrective lenses or surgery. [source: UIHealthcare.org]
  • Many people have better than 20/20 vision. In 1999 Tiger Woods had laser eye surgery, which is said to have given him 20/15 vision. After the surgery he won seven of his next ten events. [source: Independent.co.uk]
  • Here in the UK, the DVLA require you to read a 79mm number-plate character at a distance of 20 metres in order to obtain a driving licence. This equates to just 20/54 vision.
  • There is a separate DVLA requirement for visual acuity of 'decimal 0.5' (after correctives). This is just 20/40 vision, and may go some way to explaining the quality of driving here in Bristol.

Easy to read?

There is a crucial difference between text being legible and actually being easy to read. To say that something is legible is simply to say that the reader can discern what the characters are. But for something to be easy-to-read it must be larger. And of course there are other typographic factors that I shan't cover here, such as line-length, leading, typeface and so forth. There are many excellent blog posts on this subject.

Many studies have looked at at what constitutes easily-readable text. The ANSI calls for a minimum of 16 minutes of arc, and British Standard BS EN ISO 29241-3, ("Requirements for Office Work with Visual Display Terminals”) also uses 16 minutes of arc as the boundary for easily readable text. Interestingly, the apparent radius of the sun at the horizon is also 16 minutes of arc. I expect this is just coincidence, but it is interesting that there is a commonality between human visual acuity and probably the only object that has been a constant size throughout our evolution.

Text on Digital

So what affects the legibility (and by extension, readability) of text on the web? We know that this is a question of the physical size of the text and the distance of the eye from the screen. So what we really want to ask is: what affects the physical size of text on a screen? And here a number of factors come into play. Clearly the specified text size is the major factor, but perhaps less obviously there is also the pixel density of the screen, and the typeface itself.

Pixel density

Pixel density has become a significant variable in digital design only relatively recently. If you're not sure exactly what I'm talking about, pixel density is simply the number of 'dots per inch' on a screen. To illustrate, a laptop with a 1280 x 800 pixel 13 inch screen has a much lower pixel density than a 5-inch-screened smartphone of the same resolution. For reference, a pretty standard HD resolution 24 inch PC monitor has a pixel density of about 94 pixels per inch (PPI), whereas a 'Retina' screened Macbook on the other hand has around 225ppi.

Unfortunately the complexity doesn't stop there, as it is also necessary to think about device-pixel-ratios. This is to contend with the fact that many newer mobile devices are so pixel-dense that they have to 'pretend' to have lower resolution screens in order to ensure that web pages display at a size that is readable.

Interestingly, 20/20 vision should allow a person to recognise a 1 pixel pattern on a 290ppi screen held 30cm from the face. What this means is that many of us are are already using smartphone screens that exceed the capabilities of the human eye in normal use, with density values exceeding 300ppi becoming more and more common. If you've ever worked in print design, this number might seem incredible: there are now phone screens that exceed the standard quality measure for print.

Typefaces

When we talk about the physical size of text rendered on a screen, one of the things that is commonly overlooked is the differences between typefaces. Below is the letter E, set in a variety of typefaces. But each 'E' is exactly the same font size. As you can see, some fonts produce a letter E twice the height of others.

Doing the sums

So, how can you work out if the text you've put on a website will be legible? If you know the height of your capital E in pixels, then the pixel-density of the screen multiplied by the pixel-ratio should enable you to work out the physical height of the character. We can estimate the distance of the eye from the screen if we know the most likely usage for any given type of screen (i.e. handheld, sat at a desk etc). Combining these means we now know two sides of a right-angled triangle, and so we can calculate the angle made with the eye.

If all of that seems too complicated, have a look at this diagram:

If you can remember a little of your school trigonometry, you might recall that the tangent of an angle is equal to the opposite divided by the adjacent. So....

tan δ = opposite divided by adjacent = b / 2a

To save you the trouble of doing this yourself, I've made a handy little tool to do the job for you.

Enter values above to calculate legibility

About contrast

Clearly contrast of text against a background has an enormous impact on how readable it is. Understanding (and attempting to model) the impact of this will be the subject of the next post on this blog. I have written a tool which attempts to check typography for legibility both in terms of size and contrast, and I hope to share that next time, too.

Final word

Legibility is of course only one factor in making text useful and valuable. I can't really say it any better than David CarsonDon't mistake legibility for communication



Topic: Websites

Categories: Design, UX, Web design

Tags: accessibility, communication, eyesight, legibility, readability, user experience

Share: