My name is Rémi Parmentier. I go by the nickname HTeuMeuLeu. And I am an email developer. Some of you might remember me because three years ago, I had the chance to be on this stage to talk about HTML emails already. And I ended this talk with a surprise announcement…
Slide 3
… with the launch of the website Caniemail.com. It is similar to caniuse.com but for email developers. I’ve been maintaining this site for the past three years and a lot of things sure happened in the emails world.
Slide 4
Including this thing, just last month, where Microsoft had to push a quick fix to Outlook on Windows because Uber emails were crashing Outlook.
Slide 5
And the official reason from Microsoft was because the emails « used complex tables ». Which is hilarious to me, because the only reason we use tables in the first table is because Microsoft Outlook uses Word as a rendering engine and only understands tables in the first place.
Slide 6
This is a top contender for me in the Category of Email Clients That Break Because of a Thing They Force You To Do In The First Place.
Slide 7
But one of the most significant news from the past three years is the debut of dark modes in operating systems and email clients. From macOS to iOS, Android and Windows, every modern OS now features a dark mode option.
Slide 8
The idea is that you’ll check this setting on your operating system preferences, and then it’s up to any application to adjust its interface with a darker color scheme.
And this also applies to browsers and websites, and to email clients and HTML emails. But as you’d might expect, there are a few twists in emails that can make this a tiny bit more complicated.
Slide 9
In November 2020, Email Analytics tool Litmus estimated that 36% of iPhone users where opening their emails while in dark mode.
Just out of curiosity, who here uses dark mode (either on their phone or their computer)?
Slide 10
In the next 30 minutes or so, I’ll be shining the light on HTML Emails Dark Modes and share with you 5 tips to make your emails better in dark modes.
Slide 11
“modes”, plural. Because there’s not one dark mode, there are as many as there are email clients families. In this talk I’ll focus on Apple Mail, Outlook, Gmail.
Slide 12
You don’t get to chose whether your email has a dark mode or not. Email clients have something we call « Forced Dark Mode ». And if you don’t do anything your emails can look like hell. Literally.
Slide 13
Take this example from a web host. Super cute email, lovely colors and illustration. And here it is in Gmail Forced Dark Mode.
Now to be fair, Gmail since adjusted its Forced Dark Mode algorithm changes big images like this.
Slide 14
Email Developer Alice Li (@AliceLiCode) wrote a fantastic guide on Litmus about Forced Dark Mode in email clients.
Slide 15
And for some of them, like Apple Mail on macOS, there are easy tweaks to avoid getting a white color turned in black. Which is to use #fffffe instead.
Slide 16
But my most important recommendation from this entire talk is Do Not Fight Dark Mode. Embrace It. Dark Mode is a user preference, the same way a user would increase their font size or read on a small device. So DO NOT try to keep a light email in dark mode. And one part of this « Do Something » is to test. You can test on real devices.
Slide 17
Or you can use one of these Dark Mode simulator for emails tools. Like this one from Proofjump.
Slide 18
And this one that was introduced just last week in Parcel.io. Which is a fantastic email coding tool.
Slide 19
My second tip is to use transparent images.
Slide 20
Take this email from Epic Games for Fortnite. Beautiful in light mode. But in Forced Dark Mode, here in Outlook.com, you can see how every image was sliced up.
Slide 21
But be thoughtful about when to use fully transparent images. Take a look at these social icons. They look ok in light mode. But they become unreadable in dark mode in Outlook com. So here, it might be better to fill these images with a white background inside the circles.
Slide 22
And one technique I found myself using a lot is adding an outline to transparent images.
Slide 23
Take that logo from that same email. No longer readable in dark mode.
Slide 24
What I’d do in such a case is go back to Photoshop, add an Outline to that content from the background color in light mode.
Slide 25
And voilà!
Slide 26
Here’s another example.
Slide 27
And another one.
Slide 28
Of course we don’t have to go through Forced Dark Modes. And we can be more proactive. And so we can use the dark mode media query. This is something relatively new that appeared at the same time as dark mode in OS.
Slide 29
And it looks like this. […] And then inside you’d fill your classes and styles changes, just like you would in a responsive media query.
Slide 30
There are handy tools in browser DevTools to test dark mode styles. Firefox has these super handy icons to easily switch from a light mode to dark mode.
Slide 31
Chrome also has a similar option but it’s much more complicated.
Slide 32
One neat thing about the dark mode media query is you can also use it to change images.
One quirk of the dark mode media query is that for it to work in Apple Mail, on macOS or iOS, you need to add the meta tag for older versions…
Slide 35
… or the CSS property for newer versions. This is totally not a requirement on the web. But weirdly it is in Apple Mail.
Slide 36
Now the overall support for this media query is… mitigated. Works well in Apple Mail. Works in Outlook on macOS, iOS or Outlook.com. But other than that, not so much. One thing that’s been bothering me with outlook.com…
Slide 37
… is that since it includes a little icon to switch your email in dark mode or light mode. But because we’re in a webmail, using this switch doesn’t do anything if you use dark mode styles.
Slide 38
So this is my tip number 4 and how to use custom styles and make your emails properly react to outlook.com dark mode.
Slide 39
So take this piece of code. In outlook.com it would be turned like this.
Slide 40
Outlook.com applies the prefix « x_ » to any class name. This is a good practice for security.
Slide 41
And yes, that pun here was totally intended. Because not only The X Files was my favorite TV show growing up. But also because it taught me the only words I can possibly speak in German. « Ich habe keine unruhe » but maybe a little bit when coding emails.
Slide 42
Then in dark mode, Outlook.com adds these data attributes.
Slide 43
So back to our initial code…
Slide 44
The first step is to exclude Outlook.com from media query styles. For this we append a :not([class^="x_"]) pseudo-class to every class selector.
Slide 45
Then we duplicate styles only for Outlook.com using a [data-ogsb] attribute.
Slide 46
But then there’s Gmail. Gmail is really a bad student here because not only it doesn’t support the dark mode media query. But it also doesn’t have any sort of trickery or targeting to differentiate light and dark mode. And not only that, but it’s also sometimes terrible at Forced Dark Mode.
Slide 47
Especially if you already have a dark theme email. Gmail on iOS will try to invert it anyway.
Slide 48
Or this one from Google themselves.
Slide 49
This is one of favorite thing in the category of Email Clients That Break Because Of A Thing They Force You To Do In The First Place.
Slide 50
One cool thing about Gmail though is that it supports CSS Blend Modes.
Blends Modes is that thing in Photoshop that makes your developer hates you because it becomes horrible to export any individual layer.
But also Blend Modes are about blending colors from overlapping layers.
Slide 51
So let’s take this green button with white text. In Gmail in dark mode, the background color turns into a dark green, and the text turns into black.
Slide 52
Our base code looks like this:
<div style="color:#fff; background:#4d86eb;">
Get A Reward Cards
</div>
(Don’t use <div>s for buttons. This was a bad example for the sake of having less on screen.)
Slide 53
Gmail in dark mode turns it into the following:
<div style="color:#000; background:#007740;">
Get A Reward Cards
</div>
Slide 54
The first thing we’ll do is maintain the background color by using a linear-gradient. They’re well supported in Gmail and are not changed in dark mode.
Slide 55
In Gmail in dark mode, only the background-color is changed, not the background-image.
Slide 56
So this is what we have now.
Slide 57
Now let’s add blend modes into the mix. We’re going to need two blend modes. The first one will be a difference blend mode.
Slide 58
The second one will be a screen blend mode. I introduce them in this order because this is the order they’ll be applied (inside out based on the HTML).
Slide 59
If we look back at what it looks like…
Slide 60
… we can kind of represent it like this. We now have three nested layers with different background colors and blend modes. So let’s see what happens when we apply the first blend mode.
Slide 61
According to the spec, mix-blend-mode:difference “subtracts the darker of the two constituent colors from the lighter color.”
Yay, that didn’t make much sense for me either.
Slide 62
But this formula made things clearer. The result is the absolute value of the difference between our source color (Cs) and our backdrop color (Cb).
B(Cb, Cs) = |Cb - Cs|
Slide 63
So let’s see how this looks like in light mode.
Slide 64
The white text from the source color (Cs) is blended with the black from the backdrop color (Cb).
Slide 65
The white text becomes…
B(Cb, Cs) = |Cb - Cs| = |#000 - #fff| = #fff
White!
Slide 66
Now let’s do the same for the black background color from the source merged with the black background from the backdrop.
Slide 67
The black background becomes…
B(Cb, Cs) = |Cb - Cs| = |#000 - #000| = #000
Black!
Slide 68
Now let’s do the same but in dark mode.
Slide 69
The black text (changed by Gmail) from the source color (Cs) is blended with the white (changed by Gmail) from the backdrop color (Cb).
Slide 70
The black text becomes…
B(Cb, Cs) = |Cb - Cs| = |#fff - #000|
White!
Slide 71
Now let’s do the same for the white background color from the source merged with the white background from the backdrop.
Slide 72
The white background becomes…
B(Cb, Cs) = |Cb - Cs| = |#fff - #fff| = #000
Black!
Slide 73
We now end up with the same thing in both light and dark mode. So let’s apply our second blend mode!
Slide 74
According to the spec, mix-blend-mode:screen “multiplies the complements of the backdrop and source color values, then complements the result”.
Yeah, that made no sense to me either.
Slide 75
But again, the mathematical formula made it a bit clearer.
That’s all I had! To end up with a good news, Microsoft released a new version of Outlook on Windows. And for the first time in 15 years, it no longer uses Word’s rendering engine. It uses EdgeView, based on Chromium, just like in Edge.