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. Tag is what you need when you need to “break out of the box” of MJML, as Nicole put it. Basically, whenever Nicole wants to code something that doesn’t have an easy solution using MJML markup, she uses to include pure, responsive HTML.

In the first part of our exploration of MJML, we explained that components such as text, buttons and tables are always in And Keywords.

The usage of is an exception. It is an end tag that does not contain any MJML components. Instead, you use it to code like you would in a regular HTML file.

“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 . That’s what it was developed for.”

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 Section.

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:

  1. <Meta Surname=“Color scheme” Contents=“light dark”>

  2. <Meta Surname=“supported color schemes” Contents=“light dark”>

  3. </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).

  1. :root {

  2. Color scheme: light dark;

  3. supported color schemes: light dark;

  4. }

  5. @media (preferred color scheme: dark) {

  6. …Dark mode styles here…

  7. }

  8. </mj-style>

Within the Tag above: Nicole includes CSS classes for dark mode and tells email clients to hide images in light mode.

Nicole says that it is important to know how to specify CSS selectors when coding with MJML. This allows the email to be based on what you defined in the styles in the header area.

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.

  1. .dark-mode-bg>Table {

  2. Background: #1E1E1F;

  3. Background-Image: linear gradient (#fec800, #fec800) !important;

  4. }

Later, in a you would include the CSS class for the dark mode background:

background Color=“F f f” CSSClass=“Darkmode-bg”>

When this is parsed into HTML, the class goes into a

but the colors are actually on the first

so that it shows up in the cells of the table. That's why Nicole targeted tables in her dark mode styles. Otherwise, it wouldn't override the backgrounds of her tables, meaning they would still show a light background.

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:

  1. style in line=“in line”>

  2. .show {

  3. Display: none;

  4. }

  5. .hide {

  6. mso-hide: all !important;

  7. }

  8. </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.

  1. @media only screen and (min-width:480px) {

  2. .show {

  3. Display: Block !important;

  4. }

  5. .hide {

  6. Display: none !important;

  7. mso-hide: all !important;

  8. }

  9. }

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:

  1. source=“https://via.placeholder.com/600×400” CSSClass=“show” />

  2. [if !mso]>

  3. </mj-roh>

  4. source=“https://via.placeholder.com/320×400” CSSClass=“hide” />

  5. </mj-roh>

  6. </mj-column>

  7. </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 Tag above to add conditional statements in the MJML that hide mobile content from the Outlook desktop clients for Windows.

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, Day comes to the rescue once again.

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 or Label.

Nicole told me she was interested in with a regular

LEAVE A REPLY

Please enter your comment!
Please enter your name here