Dan Hollick Profile picture
Jul 21, 2021 16 tweets 5 min read Read on X
💡Have you ever wondered why the WCAG colour contrast ratio doesn't always seem to work?💡

Well it actually has to do with how we calculate colour contrast and is super interesting.

Hold on to your butts, this is a 🧵
Before we dive deeper, we should remind ourselves how colour actually works.

On screens we build a colour by adding together three different colours, Red, Green and Blue.

This is called additive colour.
For instance, this peachy colour is:
100% 🔴 + 50% 🟢 + 50% 🔵

On the web, we can get 16.7 million combinations of these values - so 16.7 million different colours.
Back to contrast... what is it actually?

Well, it's the difference in relative luminance of two colours.

Relative luminance is how bright a colour is relative to pure white, the brightest colour.
The way we calculate this is simple:

1. Get the luminance values of our colours.
A value between 0% (black) and 100%(white).

2. Divide the two values.
This gives us a ratio with a max of 21:1 and a min of 1:1
Okay, that's cool and all but why does this goof up in some cases?

Well the first problem is the way we figure out how bright a particular RGB colour is, using this equation:

Luminance = 0.2126*R + 0.7152*G + 0.0722*B
Notice how we multiply every channel by a slightly different value?

That's to accommodate for the way we perceive the brightness of the red, green and blue spectrums.

We perceive green as brighter than blue, for instance, and the equation compensates for this.
BUT, there's some dispute over how we should correct for this.

Some alternative algorithms weight the channels differently to better accommodate for human perception.

A new WCAG working draft uses this weighting:

Luminance = 0.299*R + 0.587*G + 0.114*B
Given the same colour these two approaches will produce quite different luminance values which has knock on effects for the contrast calculation:
The second problem is the contrast calculation itself, which looks like this:

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

Where L1 and L2 are the luminance values of the respective colours.

(the +0.05 is a gamma correction thing which I don't get 100%)
The problem here is that human perception of contrast isn't linear.

For example, these two sets of colours have the same contrast but we perceive the one on the right as having more contrast than the one on the left.
This is because we have a tendency to perceive higher contrast between brighter colours than between darker colours.

Modelling our perception accurately is super tricky but there are a few other ways to calculate contrast.

Here's how one of them (CIE ∆E*) effects these results
This is all compounded when you consider how old these specs are.

The sRGB spec uses an 80 nit monitor as a reference but modern displays can easily be 300 nits.

(By the way, the Pro XDR is 1000nits, 1600nits peak 🤯)
So where does this leave us?

Well the good news is lots of smarter people than you and I are working to make this better.

But it's going to take a while. Standards are difficult to change for a reason.
It's also worth pointing out that you shouldn't just ignore the WCAG contrast guidelines completely.

They are still really useful.
They just don't get it right 100% of the time.
If you want to learn more, there is an incredibly in depth discussion on the WCAG GitHub:

github.com/w3c/wcag/issue…

• • •

Missing some Tweet in this thread? You can try to force a refresh
 

Keep Current with Dan Hollick

Dan Hollick Profile picture

Stay in touch and get notified when new unrolls are available from this author!

Read all threads

This Thread may be Removed Anytime!

PDF

Twitter may remove this content at anytime! Save it as PDF for later use!

Try unrolling a thread yourself!

how to unroll video
  1. Follow @ThreadReaderApp to mention us!

  2. From a Twitter thread mention us with a keyword "unroll"
@threadreaderapp unroll

Practice here first or read more on our help page!

More from @DanHollick

Jun 8, 2023
Excited to finally share what I've been working on.

Introducing Detax, a comprehensive suite of automated tax avoidance and money laundering tools. Our goal is to revolutionise the financial fraud industry by bringing it into the 21st century.

detax.framer.website
Historically, avoiding tax has been a manual, labor intensive task which has put it out of the reach of most small businesses.

We're here to change that and open up a world of financial fraud to businesses of any size.
This is, of course, not real.

This is actually the site we're going to build in my advanced @framer course.

You can join the waitlist at advancedframer.com . Beta access in July.
Read 4 tweets
Apr 13, 2023
How does a Large Language Model like ChatGPT actually work?

Well, they are both amazingly simple and exceedingly complex at the same time.

Hold on to your butts, this is a deep dive ↓
You can think of a model as calculating the probabilities of an output based on some input.

In language models, this means that given a sequences of words they calculate the probabilities for the next word in the sequence.

Like a fancy autocomplete. Image
To understand where these probabilities come from, we need to talk about something called a neural network.

This is a network like structure where numbers are fed into one side and probabilities are spat out the other.

They are simpler than you might think.
Read 26 tweets
Mar 16, 2023
Why are some typefaces harder to read than others at the same font-size?

Well, it has a lot to do with x-height but of course it's a bit more complicated than that: ↓
You probably know this already but the x-height of a typeface is the difference between the baseline and the height of the lowercase letters.

We can also think of x-height as a ratio of the total cap height or body height.
Typically we use the letter x to determine this, hence the name.

Interestingly, curved lowercase letters like a, c, and e are often slightly taller than the x-height. They purposefully overshoot so that they appear the same visual height as x, v, w, and z.

Anyway...
Read 13 tweets
Feb 1, 2023
Why is making a dark mode greyscale so hard to get right?

Well, of course it has to do with the weird way humans perceive colour and contrast. 👇
The main issue is we we perceive contrast as higher between lighter colours.

Even though these two sets of colours have the same mathematical contrast we perceive the left as having more contrast than the right. Image
So in designs that use a lot of subtle light greys (containers, borders etc) it isn't as simple as just inverting the colour scale.

The contrast between darker greys will be lower as you can see below.
Read 16 tweets
Dec 15, 2022
Ever heard of a shader but too afraid to ask what it even means at this point?

Lets fuck around and find out 👇
First, we need to understand the difference between a CPU and GPU and why we need a separate unit just to draw graphics anyway.

(Don't worry, it's not going to be too technical.)
The thing that makes a CPU great is that it can perform a wide variety of tasks relatively quickly.

But the limitation is that each CPU core is optimised to do one thing at a time and so tasks are largely performed sequentially.
Read 19 tweets
Nov 2, 2022
Did you know these are called Boolean Operations?

That's because they use booleans to determine which part of the shapes should be visible.

Let me explain 👇 Image
To keep it simple lets use two overlapping circles.

Imagine a boolean for each circle called "inside" - for the area inside each circle the boolean is true, for the area outside it is false.

Any point within the bounding box can be represented in terms of these booleans. Image
Boolean operations are just a way of combining these booleans together to make a new shape.

Take Union for example- the new shape will consist of any area that is inside the red circle OR the blue circle. Image
Read 12 tweets

Did Thread Reader help you today?

Support us! We are indie developers!


This site is made by just two indie developers on a laptop doing marketing, support and development! Read more about the story.

Become a Premium Member ($3/month or $30/year) and get exclusive features!

Become Premium

Don't want to be a Premium member but still want to support us?

Make a small donation by buying us coffee ($5) or help with server cost ($10)

Donate via Paypal

Or Donate anonymously using crypto!

Ethereum

0xfe58350B80634f60Fa6Dc149a72b4DFbc17D341E copy

Bitcoin

3ATGMxNzCUFzxpMCHL5sWSt4DVtS8UqXpi copy

Thank you for your support!

Follow Us!

:(