A step-by-step guide to building a responsive email template with MJML: install the MJML app, add a font, an image, text and a button, then export the HTML.

Although email is an old technology, it's still preserves its popularity. According to a 2017 Zapier blog post:
The number of people using email for team communication is more than 2.5 times higher than team chat apps like Slack.

Email newsletters are great for following the industry, or getting couple of discount codes. I think I have at least 15 subscriptions to different email newsletters.
Yes, email is still popular, but there's a problem that wastes our time. At formcarry, our mission is saving people from wasting time. Creating email templates is a hassle, because there are various email clients, even though email is an old technology and doesn't support a big amount of HTML and CSS features. In general we mostly see that email templates are being created using HTML tables. Often the file is also full of unnecessary code: it's so big that you don't even want to edit it.
Thanks to the Open Source, somebody made a solution for this: MJML
MJML is made by Mailjet. It's a component based markup language that allows you to create responsive emails blazing fast and easier than ever. When you finish the project, it converts your MJML code to the HTML so you can use it for your projects.
We will code an email template design using MJML in this blog post.
I have designed a minimal email template:

MJML comes with several installing options for different platforms:
We will stick with the MJML App for this demonstration. When we open the app this screen appears

There were some good features in options, such as minifying the exported code, configuring tab size and creating snippets are the ones I liked. I also recommend you to select the minifying option for exported code, as 27 lines of MJML turns into 296 lines of HTML, and you can leverage this.
Click the New Project, enter the project's name and you'll see this screen:

You have options in there: you can go with basic empty layout or you can choose something from the gallery

We're going to code it from scratch, so let's go with single file, basic layout.

Let's observe the code. It seems there are so many things in common with HTML:
<html> and end with </html>, MJML is using the same methodology<mj-head></mj-head> is equivalent of <head></head> tags in the HTML, same way the <mj-body></mj-body> is <body></body><mj-attributes></mj-attributes> just like in the HTML <style></style>After the quick overview, let's code. First of all let's clean the unnecessary codes in our file.
<mjml>
<mj-head>
</mj-head>
<mj-body>
</mj-body>
</mjml>A reminder of our design:

I have used the Montserrat font, which is free to use, for this demo. In order to add fonts in MJML, we need to add this code right after the <mj-head>.
<mj-head>
<mj-font name="Montserrat" href="https://fonts.googleapis.com/css?family=Montserrat:400,500,600,700" />
<mj-attributes>
<mj-all font-family="Montserrat" />
</mj-attributes>
</mj-head>I also added the mj-attributes for setting Montserrat as the default font for this template.
Now I'm going to export my sample logo and paste it into the MJML project directory.
<mj-hero padding="40px">
<mj-image align="left" width="138px" src="logo.png"/>
</mj-hero>By default images aligned at center, if you want to align it to the left or right, you need to set "align" attribute.
This is how it looks right now:

Then we need 3 text elements and one button; Let's do that, we will use mj-text for texts and mj-button for button and a padding for mj-section
1<mj-section padding="40px">
2
3 <mj-column>
4
5 <mj-text>
6 Verify Your Email
7 </mj-text>
8
9 <mj-text>
10 Hi Jhony! Use the link below to verify your email
11 address.
12 </mj-text>
13
14 <mj-button>
15 It's Me, Jhony!
16 </mj-button>
17
18 <mj-text>
19 If you are not the Johny, we are sorry.
20 </mj-text>
21
22 </mj-column>
23
24</mj-section>How it looks:

Now we need to style that and finish our example. We just have to use CSS attributes in mj-text and mj-button elements.
<mj-text font-size="29px" font-weight="700" color="#222222" padding-bottom="30px">
Verify Your Email
</mj-text>
Now style the paragraph and the notice text.
<mj-text font-size="18px" color="#9798A4" font-weight="400" line-height="27px" padding-bottom="60px">
Hi Jhony! Use the link below to verify your email
address.
</mj-text>
...
<mj-text font-size="11px" color="#9798A4" font-weight="500" padding-top="30px">
If you are not the Jhony, we are sorry.
</mj-text> How it looks:

We just have to style our button right now; let's do it.
<mj-button href="#" width="100%" inner-padding="25px" border-radius="6px" background-color="#005BF2" font-size="22px" font-weight="500" color="#fff">
It's Me, Jhony!
</mj-button>Looks perfect:

Without the spaces, this is only 22 lines of code, yet when we transform it to the HTML it becomes 296 lines of code (unminified).
We can export our file in the dropdown menu. Click to the down arrow to open it.

Looks perfect. If you want to dive deeper you can take a look at MJML Documentation
Nusu Alabuga founded formcarry in 2017 and still runs it: the ingest pipeline, the spam filtering, the email delivery and the incident tracking that watches customers' forms. A product engineer by trade, with years of work in payments, security, invoicing and banking infrastructure.
WebsiteXLinkedInGitHub