Fixing Gmail’s dark mode issues with CSS Blend Modes

Since its debut in october 2019, Gmail’s dark mode has been causing a lot of headaches. It has improved and standardized over time, but there are still glaring differences between Gmail’s dark mode in iOS versus Android.

One of the most inconvenient problem in iOS in particular is that Gmail insists on changing any light text color to a dark text color. So an already dark email with white text on a black background will turn black on white. Not only does that seem counter-efficient, but it also creates real accessibility and readibility issues.

Take this email from Nest for example.

A screenshot of an already dark email from Nest in Gmail iOS in light mode (left) and dark mode (right). In dark mode, the already dark background colors are turned into light colors. The white text “Nest” included in the logo image becomes almost invisible in dark mode.

I’ve been thinking for a while about how to solve this. And CSS blend modes have been in my mind ever since they’ve been supported in Gmail. So here’s how to fix (some of) Gmail’s dark mode issues with CSS Blend Modes.

1. The base code

For this example, we’ll start by using a single

with a black background and white text.

 style="background:#000; color:#fff;">
    Lorem ipsum dolor, sit amet, consectetur adipisicing elit.

2. How Gmail transforms colors

If you open an email with the code above in Gmail iOS in dark mode, you’ll see that the colors have been changed. It’s never been clear to me how Gmail actually proceeds to do these color changes. (You still get your original colors if you try to copy and paste the email or if you forward it.) But the end result would be similar to the code below.

 style="background:#fff; color:#000;">
    Lorem ipsum dolor, sit amet, consectetur adipisicing elit.

3. Adding blend modes in the mix

Let’s go back to our initial code and let the magic of blend modes begin. We will add two inner

containers, each with a black background and a different blending mode.

 style="background:#000; color:#fff;">
     style="background:#000; mix-blend-mode:screen;">
         style="background:#000; mix-blend-mode:difference;">
            Lorem ipsum dolor, sit amet, consectetur adipisicing elit.