Monday, November 13, 2023
HomeEmail MarketingSuperior MJML Coding Strategies for E-mail Growth

Superior MJML Coding Strategies for E-mail Growth


Notes from the Dev logo yellow

It’s time for the thrilling conclusion of our journey into probably the most standard e-mail frameworks out there: MJML (Mailjet Markup Language). Okay, so it wasn’t an enormous cliffhanger or something. However we’re positively excited to share the second half of this interview with you.

After we final left Nicole Hickman, she simply completed displaying us the fundamentals of learn how to use MJML to rapidly and effectively code responsive HTML emails. This time, we’re diving a bit of deeper to find superior MJML methods.

I requested Nicole a few of the commonest questions that I’ve seen e-mail geeks questioning concerning the MJML framework. That features darkish mode, picture swapping, and overlapping content material in emails.

A part of the fantastic thing about MJML is its simplicity, as we noticed in Half 1 of this interview. However what occurs when that you must take issues a bit of additional that the framework permits? Take a look at Nicole’s ideas within the video beneath. And don’t neglect to subscribe to Sinch E-mail on Acid on YouTube to catch new episodes of Notes from the Dev: Video Version.

(Go to our Useful resource Heart to view the total transcription of this episode) 

Introducing the <mj-raw> tag

In terms of superior MJML methods and conventional HTML e-mail growth, there’s a method you may get the perfect of each worlds.

I’ll reduce to the chase right here. The <mj-raw> tag is what you’ll want when you need to “escape of the field” of MJML, as Nicole put it. Principally, every time she needs to code one thing for which there’s no easy answer with MJML markup, Nicole makes use of <mj-raw> to incorporate uncooked, responsive HTML.

Within the first installment of our exploration into MJML, you’ll recall how Nicole defined that elements like textual content, buttons, and tables all the time get enclosed in <mj-section> and <mj-column> tags.

Using <mj-raw> is an exception. It’s an ending tag that gained’t embrace any MJML elements. As an alternative, you employ it to code the identical method you’ll in a traditional HTML file.

“There are a variety of issues that MJML can do all by itself. However in case you have the necessity to do one thing that may be a bit of extra cumbersome to attempt to do throughout the MJML itself, you may actually bust out and simply wrap issues in <mj-raw>. That’s what it was developed for.”

Nicole Hickman, Direct Advertising and marketing Developer, Fishawack Well being

To place it one other method, you’re not utterly tied to the MJML framework if you use it to develop responsive emails.

Darkish mode and MJML

When Nicole confirmed us how she creates emails with darkish and lightweight variations, she defined that a variety of it takes place up within the <mj-head> part.

Should you’ve seen any tutorials on learn how to code darkish mode emails, you’ll acknowledge the meta tags which can be used to let e-mail shoppers know that your code provides each mild and darkish mode variations:

  1. <mj-raw>

  2. <meta identify="color-scheme" content material="mild darkish">

  3. <meta identify="supported-color-schemes" content material="mild darkish">

  4. </mj-raw>

Beneath the usual CSS styling in Nicole’s boilerplate for this e-mail format is the place she continues including and defining darkish mode types, utilizing a root selector and the media question (prefers-color-scheme: darkish).

  1. <mj-style>

  2. :root {

  3.    color-scheme: mild darkish;

  4.    supported-color-schemes: mild darkish;

  5. }

  6.  

  7. @media (prefers-color-scheme: darkish) {

  8. ...darkish mode types right here...

  9. }

  10. </mj-style>

Within the <mj-style> tag above, Nicole consists of darkish mode CSS courses and tells e-mail shoppers to cover mild mode photographs.

Nicole says it’s necessary to know learn how to specify CSS selectors when coding with MJML. That’s what permits the e-mail to change to darkish mode preferences (background coloration, textual content coloration, and many others.) inside an <mj-section> based mostly on what you outlined within the types inside the pinnacle part.

That’s why, for instance, Nicole used a right-angled bracket in her darkish mode types when defining the background coloration for tables in darkish mode.

  1. .dark-mode-bg>desk {

  2. background: #1E1E1F;

  3. background-image: linear-gradient (#fec800, #fec800) !necessary;

  4. }

Later, in an <mj-section>, you’d embrace the CSS class for the darkish mode background: 

<mj-section background coloration="fff" css-class="dark-mode-bg"> 

When this will get parsed to HTML, the category goes right into a <div>, however the colours truly get utilized to the primary <td> in order that it seems within the cells of the desk. That’s why Nicole focused desk in her darkish mode types. In any other case, it wouldn’t override the backgrounds on her tables, which suggests they’d nonetheless present a light-weight mode background.

Watching the way in which different builders work is superb! Nicole had me rethinking the way in which I goal darkish mode. However we’ll have to save lots of all that for one more episode.

Picture swapping and MJML

One other query individuals have about extra superior MJML entails picture swapping. Many occasions, you’ll need a picture that’s one measurement for desktop viewing and a unique measurement that’s optimized for cell units.

By the way in which, Nicole takes a “cell first” strategy to e-mail growth. For picture swapping, meaning she finally ends up doing one thing which will seem to be counterintuitive.

Within the first grouping of types, she consists of something which will have to be utilized inline to the tag. Nicole does this as a result of GANGA (Gmail App with Non-Google Accounts) doesn’t help media queries, that are used for focusing on totally different display screen sizes.

So, by making use of the next code, she will be able to inform e-mail shoppers to point out a sure picture on desktop however not cell:

  1. <mj-model inline="inline">

  2. .present {

  3. show: none;

  4. }

  5.  

  6. .cover {

  7. mso-hide: all !necessary;

  8. }

  9. </mj-style>

Nicole additionally applies these courses to the media question as you’d count on. Nonetheless, by including !necessary; to the tip (see beneath) it overrides something within the desktop view.

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

  2. .present {

  3. show: block !necessary;

  4. }

  5.  

  6. .cover {

  7. show: none !necessary;

  8. mso-hide: all !necessary;

  9. }

  10. }

Lastly, right here’s a take a look at the MJML code within the physique of Nicole’s e-mail by which she consists of each a 600 x 400 placeholder picture for desktop and a 320 x 400 placeholder picture for cell units whereas making use of the suitable courses:

  1. <mj-section>

  2. <mj-column>

  3. <mj-image src="https://by way of.placeholder.com/600x400" css-class="present” />

  4. <mj-raw>

  5. <!—[if !mso]><!---->

  6. </mj-raw>

  7. <mj-image src="https://by way of.placeholder.com/320x400" css-class="cover" />

  8. <mj-raw>

  9. <!--<[endif]-->

  10. </mj-raw>

  11. </mj-column>

  12. </mj-section>

When Nicole switches over to the parsed HTML, we see that the inline class is show: none. However as a result of she used show: block together with !necessary; that overrides the inline setting.

Additionally, discover that Nicole makes use of the <mj-raw> tag above so as to add conditional statements within the MJML that cover cell content material from Outlook’s desktop shoppers for Home windows.

Overlapping content material and MJML

One other method that skilled e-mail builders use usually is overlapping parts in a design. For instance, you might have considered trying reside textual content overlayed on high of a graphic. That method, the e-mail is accessible for display screen reader utilization, and essential copy will present up even when the recipient has photographs turned off.

To make this occur in MJML, the <mj-raw> tag as soon as once more involves the rescue.

Nicole used some superior types, which e-mail super-geeks Mark Robbins, Steven Sayo, and Rémi Parmentier shared with the group. You’ll be able to study extra about these strategies for overlay and absolute positioning from Steven Sayo on Medium and from a put up on Good E-mail Code by Mark Robbins.

When you’ve discovered learn how to use these code snippets to attain the sort of overlapping you need, it’s so simple as putting it into both an <mj-style> or <mj-raw> tag.

Nicole informed me she selected to make use of <mj-raw> with a daily <model> tag for organizational functions as a result of she wished to maintain it as its personal separate string.

Let the experimentation start

Now that you simply’ve been launched to the fundamentals of this e-mail framework and a few superior MJML coding methods, it’s time to start out enjoying round.

Nicole talked about a number of occasions that she did must experiment with issues a bit to get all of this to work. However for those who ask me, that’s a part of the enjoyable of being an e-mail developer.

And right here’s some excellent news… Nicole says that the MJML Group on Slack is tremendous pleasant and useful. So, as you begin making an attempt out superior MJML methods and hit roadblocks, head over there to ask questions and make connections.

Talking of connecting… we’re simply getting began with Notes from the Dev: Video Version. There are extra nice ideas, tips, and tutorials coming your method quickly. Be sure to subscribe on YouTube so that you aren’t unnoticed.



Writer: Megan Boshuyzen

Megan is a graphic designer turned e-mail developer who’s labored on all features of e-mail advertising. She believes good emails for good causes make a constructive distinction on this planet. Megan is at the moment working as an e-mail developer for Sinch E-mail. Go to her web site and study extra at megbosh.com.

Writer: Megan Boshuyzen

Megan is a graphic designer turned e-mail developer who’s labored on all features of e-mail advertising. She believes good emails for good causes make a constructive distinction on this planet. Megan is at the moment working as an e-mail developer for Sinch E-mail. Go to her web site and study extra at megbosh.com.

RELATED ARTICLES

LEAVE A REPLY

Please enter your comment!
Please enter your name here

Most Popular

Recent Comments