Create your very own Auto Publish News/Blog Site and Earn Passive Income in Just 4 Easy Steps
It's time for the exciting conclusion of our journey into one of the most popular email frameworks available: MJML (Mailjet Markup Language). Okay, it wasn't a big cliffhanger or anything. But we're definitely excited to share the second half of this interview with you.
When we last left Nicole Hickman, she had just shown us the basics of how to use MJML to quickly and efficiently code responsive HTML emails. This time, we're diving a little deeper and discovering more advanced MJML techniques.
I asked Nicole some of the most common questions I've seen among email geeks about the MJML framework, including dark mode, image swapping, and overlapping content in emails.
Part of the beauty of MJML is its simplicity, as we saw in Part 1 of this interview. But what happens when you need to push things a little further than the framework allows? Check out Nicole's tips in the video below. And don't forget to subscribe to Sinch Email on Acid on YouTube to see new episodes of Notes from the Dev: Video Edition.
(Visit our Resource Center to view the full transcript of this episode.)
We introduce: label
When it comes to advanced MJML techniques and traditional HTML email development, there is a way to get the best of both worlds.
I'll get straight to the point.
In the first part of our exploration of MJML, we explained that components such as text, buttons and tables are always in
The usage of
“There are many things that MJML can do all by itself. But if you need to do something that would be a bit more cumbersome within MJML itself, you can of course just do it in
Nicole Hickman, Direct Marketing Developer, Fishawack Health
In other words, you are not completely tied to the MJML framework when you use it to develop responsive emails.
Dark mode and MJML
When Nicole showed us how she creates emails with dark and light versions, she explained that much of it is at the top of the
If you've watched tutorials on coding emails in dark mode, you'll recognize the meta tags that let email clients know that your code offers both light and dark mode versions:
-
-
<Meta Surname=“Color scheme” Contents=“light dark”>
-
<Meta Surname=“supported color schemes” Contents=“light dark”>
-
</mj-roh>
Below the default CSS styling in Nicole's boilerplate for this email layout, she adds and defines additional dark mode styles using a root selector and the media query (prefers-color-scheme: dark).
-
-
:root {
-
Color scheme: light dark;
-
supported color schemes: light dark;
-
}
-
@media (preferred color scheme: dark) {
-
…Dark mode styles here…
-
}
-
</mj-style>
Within the
Nicole says that it is important to know how to specify CSS selectors when coding with MJML. This allows the email to be
That's why, for example, Nicole used a right angle bracket in her dark mode styles when defining the background color for tables in dark mode.
-
.dark-mode-bg>Table {
-
Background: #1E1E1F;
-
Background-Image: linear gradient (#fec800, #fec800) !important;
-
}
Later, in a
When this is parsed into HTML, the class goes into a
It's amazing to see other developers at work! Nicole made me rethink my direction on dark mode. But we'll have to save all that for another episode.
Image exchange and MJML
Another question people have about more advanced MJML is about image replacement. Often you'll want an image in one size for desktop viewing and another size optimized for mobile devices.
By the way, Nicole takes a mobile-first approach to email development. When it comes to image sharing, that means she ends up doing something that might seem counterintuitive.
In the first style group, she includes anything that might need to be applied inline to the tag. Nicole does this because GANGA (Gmail app with non-Google accounts) doesn't support media queries used to target different screen sizes.
By applying the following code, she can instruct email clients to display a specific image on desktop but not on mobile devices:
-
style in line=“in line”> -
.show {
-
Display: none;
-
}
-
.hide {
-
mso-hide: all !important;
-
}
-
</mj-style>
Nicole applies these classes to the media query as expected, but adding !important; at the end (see below) overrides everything in the desktop view.
-
@media only screen and (min-width:480px) {
-
.show {
-
Display: Block !important;
-
}
-
.hide {
-
Display: none !important;
-
mso-hide: all !important;
-
}
-
}
Finally, here's a look at the MJML code in the body of Nicole's email, where she inserts both a 600 x 400 placeholder image for desktop and a 320 x 400 placeholder image for mobile devices using the appropriate classes:
-
-
-
source =“https://via.placeholder.com/600×400” CSSClass=“show” /> -
-
[if !mso]>
-
</mj-roh>
-
source =“https://via.placeholder.com/320×400” CSSClass=“hide” /> -
-
-
</mj-roh>
-
</mj-column>
-
</mj-section>
When Nicole switches to the parsed HTML, we see that the inline class is display: none. However, because she used display: block along with !important;, the inline setting is overridden.
Please also note that Nicole
Overlapping content and MJML
Another technique experienced email designers regularly use is to overlap elements in a design. For example, you may want to overlay live text on top of a graphic. This way, the email is accessible for use by screen readers and important text will be displayed even if the recipient has turned off images.
To enable this in MJML,
Nicole used some advanced styles that email supergeeks Mark Robbins, Steven Sayo, and Rémi Parmentier shared with the community. You can learn more about these overlay and absolute positioning methods from Steven Sayo on Medium and from a post by Mark Robbins on Good Email Code.
Once you have figured out how to use these code snippets to achieve the desired overlap, it is quite easy to either insert them into a
Nicole told me she was interested in