1. Start Your HTML E-mail Doc
To start with, it’s price mentioning the place I pulled among the assets from.
Now, as we mentioned within the earlier tutorial, you’ll want to start your HTML electronic mail template with an HTML doctype, and the proper language in your subscribers. On this case we’re going to use the HTML5 doctype, set our language to English with <html lang="en">
, and likewise embody the XML and Microsoft Workplace namespaces (the xmlns
bits). We’re going to want these just a few traces down, as I will clarify.
1 |
<!DOCTYPE html>
|
2 |
<html lang="en" xmlns="http://www.w3.org/1999/xhtml" xmlns:o="urn:schemas-microsoft-com:workplace:workplace"> |
3 |
<head>
|
4 |
<meta charset="UTF-8"> |
5 |
<meta identify="viewport" content material="width=device-width,initial-scale=1"> |
6 |
<meta identify="x-apple-disable-message-reformatting"> |
7 |
<title></title>
|
8 |
<!--[if mso]>
|
9 |
<noscript>
|
10 |
<xml>
|
11 |
<o:OfficeDocumentSettings>
|
12 |
<o:PixelsPerInch>96</o:PixelsPerInch>
|
13 |
</o:OfficeDocumentSettings>
|
14 |
</xml>
|
15 |
</noscript>
|
16 |
<![endif]-->
|
17 |
<type>
|
18 |
desk, td, div, h1, p {font-family: Arial, sans-serif;} |
19 |
desk, td {border:2px strong #000000 !necessary;} |
20 |
</type>
|
21 |
</head>
|
22 |
</html>
|
There are fairly just a few issues within the code above, however it’s the naked minimal it’s essential to guarantee your ultimate electronic mail renders fantastically in all places.
Firstly, now we have just a few meta
tags to make sure the precise textual content encoding, viewport scaling throughout completely different cell gadgets, and one to cease Apple from adjusting the dimensions in a wierd method of their mail apps.
Beneath the <title></title>
tag you will see some code between <!--[if mso]>
and <![endif]-->
. Inserting code inside these two tags signifies that solely Microsoft Outlook on Home windows will apply it (mso = ‘Microsoft Outlook’). And in there, now we have a small quantity of XML that may make sure that PNG photographs show on the proper measurement in Outlook on Home windows. The xlmns
settings that we put within the html
tag ensures this code will get interpreted correctly.
Beneath that, now we have a type
tag with simply a few CSS guidelines. The primary units the font for all our important components, and that is for the good thing about Gmail webmail, which can override our font settings except we embody this. If you find yourself altering your fonts later, you should definitely make the change right here too.
Lastly, we’re together with desk, td {border:2px strong #000000 !necessary;}
which can draw a border on all the pieces. That is purely in order that we are able to see what we’re doing as we construct, and we’ll take away it on the finish.
With that sorted, we are able to start constructing the remainder of the construction.
2. Create the Physique and Important Desk
First, we’ll add an total construction for our electronic mail, beginning with a <physique>
tag. Add the code under straight beneath the </head>
tag:
1 |
<physique type="margin:0;padding:0;"> |
2 |
<desk position="presentation" type="width:100%;border-collapse:collapse;border:0;border-spacing:0;background:#ffffff;"> |
3 |
<tr>
|
4 |
<td align="heart" type="padding:0;"> |
5 |
Howdy! |
6 |
</td>
|
7 |
</tr>
|
8 |
</desk>
|
9 |
</physique>
|
You may see the margin and padding on the physique tag are set to zero to keep away from any sudden house.
We’ve additionally added a desk with a width of 100%. This acts as a real physique tag for our electronic mail, as a result of the physique tag is typically eliminated by electronic mail purchasers. Apply any ‘physique’ background color that you simply need to this desk tag.
All our tables will likely be set to position="presentation"
. This makes them extra accessible, because it tells display readers to deal with it as a visible desk, not an information desk.
We’ve set border-collapse
to collapse
, and each border
and border-spacing
to zero to keep away from any sudden house within the desk.
You may discover we’re utilizing <td align="heart">
, and if you happen to’re already conversant in HTML you may be questioning why, since align
is definitely a deprecated HTML property. We use it as a result of electronic mail purchasers differ so broadly of their stage of CSS help, and sometimes we nonetheless want to make use of deprecated HTML to make sure all the pieces shows correctly in all places. On this occasion, it’s as a result of Outlook for Home windows doesn’t obey margin:0 auto;
in CSS to heart issues.
Lastly, be sure to at all times set the padding in your desk cells to zero within the inline kinds, e.g. <td type="padding:0;">
, in any other case electronic mail purchasers will all add their very own quantity of padding. After we do add padding ourselves, we are able to modify this worth, but when there isn’t any padding to be utilized to any of the perimeters, it’s essential to explicitly set it to zero.



A Word on Utilizing CSS Padding Shorthand
When utilizing CSS padding on desk cells, you’ll be able to reliably write it 3 ways. Both specify one worth, e.g. padding:20px
which can apply 20 pixels of padding to each aspect of your cell (prime, proper, backside and left), or specify padding in pairs, i.e. padding: 10px 20px
, which can add 10 pixels padding to each prime and backside, plus 20 pixels to each left and proper. If neither of these are appropriate, it’s best to declare each aspect, i.e. padding: 10px 10px 0 5px
. In all instances it’s essential to set every worth, even when a few of them are zero. Moreover, solely specifying three values can have unpredictable outcomes throughout electronic mail purchasers.
Padding works reliably on desk cells in all electronic mail purchasers, however in case you are having bother with padding, there isn’t any must resort to spacer GIFs. In a pinch you should utilize spacer divs or spacer cells. Simply embody a non-breaking house character (
) inside, set an identical peak
and line peak
, and you should definitely embody mso-line-height-rule:precisely
which can guarantee Microsoft Outlook for Home windows renders it on the pixel-perfect measurement. (In case you are creating horizontal house, it’s essential to specify a width
as a substitute of peak, and will must additionally add font-size:0;
.) Right here is an instance or a spacer cell inside a row:
1 |
<tr><td type="line-height:10px;peak:10px;mso-line-height-rule:precisely;"> </td></tr> |
And here’s a spacer div:
1 |
<div type="line-height:10px;peak:10px;mso-line-height-rule:precisely;"> </div> |
Including the Important Desk
Now let’s place a desk of 602 pixels huge contained in the container desk.
600 pixels is a secure most width in your emails to show comfortably inside most desktop and webmail purchasers on most display resolutions, and we’re including 2 pixels so we are able to have a 1 pixel border across the exterior, which provides a pixel on both aspect.
We’ll change our little ‘Howdy!’ greeting with this desk.
1 |
<desk position="presentation" type="width:602px;border-collapse:collapse;border:1px strong #cccccc;border-spacing:0;text-align:left;"> |
2 |
<tr>
|
3 |
<td type="padding:0;"> |
4 |
Howdy! |
5 |
</td>
|
6 |
</tr>
|
7 |
</desk>
|
Nice! Now now we have our outer desk, and our important content material desk sitting inside, prepared for some rows of content material.



3. Create the HTML E-mail Template Construction and Header
In our electronic mail design we are able to see that the structure is split into just a few logical sections, so we’ll create a row for every.
Let’s duplicate the only row within the final desk we added in order that now we have three in complete, by copying all the pieces between (and together with) the <tr>
and </tr>
and pasting it two occasions beneath.
I’ve modified the ‘Howdy!’ textual content to learn Row 1, Row 2 and Row 3 so it ought to now appear like this:
1 |
<desk position="presentation" type="width:602px;border-collapse:collapse;border:1px strong #cccccc;border-spacing:0;text-align:left;"> |
2 |
<tr>
|
3 |
<td type="padding:0;"> |
4 |
Row 1 |
5 |
</td>
|
6 |
</tr>
|
7 |
<tr>
|
8 |
<td type="padding:0;"> |
9 |
Row 2 |
10 |
</td>
|
11 |
</tr>
|
12 |
<tr>
|
13 |
<td type="padding:0;"> |
14 |
Row 3 |
15 |
</td>
|
16 |
</tr>
|
17 |
</desk>
|



Now we’ll color them based on the design by including a background
CSS property to the type
tag. At all times bear in mind to make use of the complete six characters of a hexadecimal code like #ffffff
, as three character shorthand like #fff
gained’t at all times work in all electronic mail purchasers.
1 |
<desk position="presentation" type="width:602px;border-collapse:collapse;border:1px strong #cccccc;border-spacing:0;text-align:left;"> |
2 |
<tr>
|
3 |
<td type="padding:0;background:#70bbd9;"> |
4 |
Row 1 |
5 |
</td>
|
6 |
</tr>
|
7 |
<tr>
|
8 |
<td type="padding:0;"> |
9 |
Row 2 |
10 |
</td>
|
11 |
</tr>
|
12 |
<tr>
|
13 |
<td type="padding:0;background:#ee4c50;"> |
14 |
Row 3 |
15 |
</td>
|
16 |
</tr>
|
17 |
</desk>
|



Okay, subsequent up in our electronic mail design we’re going to concentrate on Row 1. On the cell, let’s change the padding from 0
to 40px 0 30px 0
. Then contained in the cell we’ll insert our picture:
1 |
<td align="heart" type="padding:40px 0 30px 0;background:#70bbd9;"> |
2 |
<img src="photographs/h1.png" alt="" width="300" type="peak:auto;show:block;" /> |
3 |
</td>
|
At all times specify the width of your photographs utilizing the HTML width attribute moderately than CSS, e.g. width="300"
as seen above, moderately than type="width:300px;"
. When you do not, Microsoft Outlook for Home windows will show your picture at its bodily measurement.
We’ve additionally set the picture peak
to auto
to keep away from any squishing, and show
to block
, which prevents gaps from showing beneath it in some electronic mail purchasers.
Lastly, in case your picture incorporates necessary info that is not talked about in your electronic mail’s textual content, you should definitely add an outline of it to the alt
tag in order that will probably be introduced by display readers to these utilizing them.
Word: Photographs do not at all times load and alt textual content isn’t at all times visually displayed as a fallback, so any essential info ought to at all times be included as reside textual content in your electronic mail moderately than being embedded in a picture.
And that’s our HTML header carried out!



4. Create the Content material Space
Transferring on from the header, let’s now consider our HTML electronic mail’s content material space. First off, we’ll add some padding to the Row 2’s cell in order that the desk inside has some house round it, as per our design, in order that it now seems like this:
1 |
<tr>
|
2 |
<td type="padding:36px 30px 42px 30px;"> |
3 |
Row 2 |
4 |
</td>
|
5 |
</tr>
|



Now we’ll change the ‘Row 2’ textual content with one other desk to nest our important content material inside. When constructing HTML electronic mail utilizing tables, we have to nest them as a result of colspan
and rowspan
will not be broadly supported throughout electronic mail purchasers.
1 |
<desk position="presentation" type="width:100%;border-collapse:collapse;border:0;border-spacing:0;"> |
2 |
<tr>
|
3 |
<td type="padding:0;"> |
4 |
Row 1 |
5 |
</td>
|
6 |
</tr>
|
7 |
<tr>
|
8 |
<td type="padding:0;"> |
9 |
Row 2 |
10 |
</td>
|
11 |
</tr>
|
12 |
</desk>
|
We’ve set the width of this desk to 100%. It’s good observe to make use of share widths moderately than utilizing a pixel worth wherever potential as a result of this can aid you additional down the monitor if you wish to make your electronic mail responsive, and even if you happen to merely want to regulate the width of your electronic mail in a while. Proportion widths will mechanically adapt to a brand new container measurement, whereas pixel widths would all have to be individually up to date.



Now we’ll add our content material to the highest row, which is a heading, a paragraph of textual content, and a ultimate paragraph with a hyperlink inside. At this stage, we aren’t including any styling in any respect to those components.



Exchange the ‘Row 1’ textual content with the next:
1 |
<h1>Creating E-mail Magic</h1> |
2 |
<p>Lorem ipsum dolor sit amet, consectetur adipiscing elit. In tempus adipiscing felis, sit amet blandit ipsum volutpat sed. Morbi porttitor, eget accumsan et dictum, nisi libero ultricies ipsum, posuere neque at erat.</p> |
3 |
<p><a href="http://www.instance.com">In tempus felis blandit</a></p> |
Subsequent we’re going so as to add our two columns of content material to Row 2. As a result of we wish a niche in between these two cells, we’ll create a three-column desk with an empty cell between the 2 outer columns. There are just a few methods to create this structure, however this one is probably the most dependable for our functions.
As a lot as I like to stay to percentages, when you’ve content material that may be a particular measurement, it may be difficult to transform it to a share (on this instance, the columns can be 48.1% which may change into complicated). Because of this, since our two photographs are 260px huge, we’ll create columns which can be additionally 260px huge, with a 20px margin cell within the center. (This may complete 540px, which is the 600px width of our desk minus the padding of 30px on both aspect.) Make sure you zero your font-size
and line-height
and add a non-breaking house character
within the center cell.
We’ll additionally set the vertical-align
to prime
for each cells in order that they may vertically align to the highest, even when one column has extra textual content than the opposite. The default vertical alignment is center
.
Exchange ‘Row 2’ with this desk:
1 |
<desk position="presentation" type="width:100%;border-collapse:collapse;border:0;border-spacing:0;"> |
2 |
<tr>
|
3 |
<td type="width:260px;padding:0;vertical-align:prime;"> |
4 |
Column 1 |
5 |
</td>
|
6 |
<td type="width:20px;padding:0;font-size:0;line-height:0;"> </td> |
7 |
<td type="width:260px;padding:0;vertical-align:prime;"> |
8 |
Column 2 |
9 |
</td>
|
10 |
</tr>
|
11 |
</desk>
|



Now let’s add our photographs and content material to these columns. Margins are very effectively supported on <p>
tags throughout all electronic mail purchasers, so we are going to wrap our textual content and pictures in <p>
tags and modify the spacing between them utilizing margin
later after we add all our textual content styling.
Let’s add content material to Columns 1 and a couple of in order that the entire desk now seems like this:
1 |
<desk position="presentation" type="width:100%;border-collapse:collapse;border:0;border-spacing:0;"> |
2 |
<tr>
|
3 |
<td type="width:260px;padding:0;vertical-align:prime;"> |
4 |
<p><img src="photographs/left.gif" alt="" width="260" type="peak:auto;show:block;" /></p> |
5 |
<p>Lorem ipsum dolor sit amet, consectetur adipiscing elit. In tempus adipiscing felis, sit amet blandit ipsum volutpat sed. Morbi porttitor, eget accumsan dictum, est nisi libero ultricies ipsum, in posuere mauris neque at erat.</p> |
6 |
<p><a href="http://www.instance.com">Blandit ipsum volutpat sed</a></p> |
7 |
</td>
|
8 |
<td type="width:20px;padding:0;font-size:0;line-height:0;"> </td> |
9 |
<td type="width:260px;padding:0;vertical-align:prime;"> |
10 |
<p><img src="photographs/proper.gif" alt="" width="260" type="peak:auto;show:block;" /></p> |
11 |
<p>Morbi porttitor, eget est accumsan dictum, nisi libero ultricies ipsum, in posuere mauris neque at erat. Lorem ipsum dolor sit amet, consectetur adipiscing elit. In tempus adipiscing felis, sit amet blandit ipsum volutpat sed.</p> |
12 |
<p><a href="http://www.instance.com">In tempus felis blandit</a></p> |
13 |
</td>
|
14 |
</tr>
|
15 |
</desk>
|
Right here we’ve set the width of the pictures utilizing the HTML width
attribute once more, similar to we did after we inserted the header picture.



5. Model the E-mail Template Footer
Now we’ll add our padding to the footer row.
1 |
<tr>
|
2 |
<td type="padding:30px;background:#ee4c50;"> |
3 |
Row 3 |
4 |
</td>
|
5 |
</tr>
|



Inside that cell, we’ll change the ‘Row 3’ textual content with one other desk to get two columns, every 50% huge, with the left set to align="left"
and proper to align="proper"
in order that the content material in every will likely be pinned to these sides and provides us a balanced electronic mail design.
1 |
<desk position="presentation" type="width:100%;border-collapse:collapse;border:0;border-spacing:0;"> |
2 |
<tr>
|
3 |
<td type="padding:0;width:50%;" align="left"> |
4 |
Left Column |
5 |
</td>
|
6 |
<td type="padding:0;width:50%;" align="proper"> |
7 |
Proper Column |
8 |
</td>
|
9 |
</tr>
|
10 |
</desk>
|



Exchange ‘Left Column’ with a paragraph of textual content:
1 |
<p>® Somebody, Someplace 2021<br/><a href="http://www.instance.com">Unsubscribe</a></p> |
We’ll create one other little desk for our social media icons, because it’s the easiest way to get probably the most exact spacing that renders correctly in all places. Exchange the ‘Proper Column’ textual content with the desk under.
You may discover we aren’t specifying a desk width, and that is in order that the width of the desk will likely be decided by the cells inside. They’re every 38px huge (the width of our icons) plus 10px padding on the left.
1 |
<desk position="presentation" type="border-collapse:collapse;border:0;border-spacing:0;"> |
2 |
<tr>
|
3 |
<td type="padding:0 0 0 10px;width:38px;"> |
4 |
<a href="http://www.twitter.com/"><img src="photographs/tw.png" alt="Twitter" width="38" type="peak:auto;show:block;border:0;" /></a> |
5 |
</td>
|
6 |
<td type="padding:0 0 0 10px;width:38px;"> |
7 |
<a href="http://www.fb.com/"><img src="photographs/fb.png" alt="Fb" width="38" type="peak:auto;show:block;border:0;" /></a> |
8 |
</td>
|
9 |
</tr>
|
10 |
</desk>
|



And there now we have it; our HTML electronic mail template structure is full!
6. Model the Textual content
Styling the textual content inside our HTML electronic mail template is a very necessary step. First, let’s take a look at the highest row of content material with our h1
and introductory textual content.
Essential Word when utilizing Paragraph and Heading Tags
When utilizing paragraph and heading tags (p, h1, h2, and so on.) it’s essential to specify your prime and backside margin settings, in any other case every electronic mail shopper will apply their very own wildly completely different default margins to those components. You additionally want to ensure your prime and backside margins are set to zero if you do not need any in any respect, during which case you’ll set your heading to margin:0;
. When you solely desire a backside margin, it’s best to nonetheless set the highest margin to zero, e.g. margin:0 0 10px 0;
.
With that in thoughts, we’ll set our desired margins on all our tags, and we additionally need to set the textual content color to be #153643
, which we are able to apply to the cell, as all the pieces inside will inherit that color. After these modifications, the entire cell seems like this:
1 |
<td type="padding:0 0 36px 0;coloration:#153643;"> |
2 |
<h1 type="font-size:24px;margin:0 0 20px 0;font-family:Arial,sans-serif;">Creating E-mail Magic</h1> |
3 |
<p type="margin:0 0 12px 0;font-size:16px;line-height:24px;font-family:Arial,sans-serif;">Lorem ipsum dolor sit amet, consectetur adipiscing elit. In tempus adipiscing felis, sit amet blandit ipsum volutpat sed. Morbi porttitor, eget accumsan et dictum, nisi libero ultricies ipsum, posuere neque at erat.</p> |
4 |
<p type="margin:0;font-size:16px;line-height:24px;font-family:Arial,sans-serif;"><a href="http://www.instance.com" type="coloration:#ee4c50;text-decoration:underline;">In tempus felis blandit</a></p> |
5 |
</td>
|
You may discover above that now we have additionally set the font-family
on each particular person h1
and p
factor, and also you may be questioning why we will not simply set this on the physique or desk tag. It is because some webmail purchasers will override your font if you happen to do not set them inline on every paragraph or heading factor. There are different issues and approaches to this challenge, however for simplicity’s sake and to make sure our electronic mail renders completely in all places at this stage, we are going to set it inline on every factor.
Now, shifting all the way down to our two-column space, add the coloration
to every of the 260px huge cells in order that they each appear like this:
1 |
<td type="width:260px;padding:0;vertical-align:prime;coloration:#153643;"> |
As above, we’ll add some textual content styling and margins to our paragraphs and hyperlinks, and set a base font measurement to the whole desk. All collectively, the desk now seems like this:
1 |
<desk position="presentation" type="width:100%;border-collapse:collapse;border:0;border-spacing:0;"> |
2 |
<tr>
|
3 |
<td type="width:260px;padding:0;vertical-align:prime;coloration:#153643;"> |
4 |
<p type="margin:0 0 25px 0;font-size:16px;line-height:24px;font-family:Arial,sans-serif;"><img src="photographs/left.gif" alt="" width="260" type="peak:auto;show:block;" /></p> |
5 |
<p type="margin:0 0 12px 0;font-size:16px;line-height:24px;font-family:Arial,sans-serif;">Lorem ipsum dolor sit amet, consectetur adipiscing elit. In tempus adipiscing felis, sit amet blandit ipsum volutpat sed. Morbi porttitor, eget accumsan dictum, est nisi libero ultricies ipsum, in posuere mauris neque at erat.</p> |
6 |
<p type="margin:0;font-size:16px;line-height:24px;font-family:Arial,sans-serif;"><a href="http://www.instance.com" type="coloration:#ee4c50;text-decoration:underline;">Blandit ipsum volutpat sed</a></p> |
7 |
</td>
|
8 |
<td type="width:20px;padding:0;font-size:0;line-height:0;"> </td> |
9 |
<td type="width:260px;padding:0;vertical-align:prime;coloration:#153643;"> |
10 |
<p type="margin:0 0 25px 0;font-size:16px;line-height:24px;font-family:Arial,sans-serif;"><img src="photographs/proper.gif" alt="" width="260" type="peak:auto;show:block;" /></p> |
11 |
<p type="margin:0 0 12px 0;font-size:16px;line-height:24px;font-family:Arial,sans-serif;">Morbi porttitor, eget est accumsan dictum, nisi libero ultricies ipsum, in posuere mauris neque at erat. Lorem ipsum dolor sit amet, consectetur adipiscing elit. In tempus adipiscing felis, sit amet blandit ipsum volutpat sed.</p> |
12 |
<p type="margin:0;font-size:16px;line-height:24px;font-family:Arial,sans-serif;"><a href="http://www.instance.com" type="coloration:#ee4c50;text-decoration:underline;">In tempus felis blandit</a></p> |
13 |
</td>
|
14 |
</tr>
|
15 |
</desk>
|
Lastly, we’ll type the footer. Firstly, we’ll add some font styling to the principle footer desk, inside our crimson footer cell with the 30px padding, in order that it now reads:
1 |
<td type="padding:30px;background:#ee4c50;"> |
2 |
<desk position="presentation" type="width:100%;border-collapse:collapse;border:0;border-spacing:0;font-size:9px;font-family:Arial,sans-serif;"> |
Within the left column of this desk, we are able to replace our paragraph and hyperlink to incorporate type and color:
1 |
<p type="margin:0;font-size:14px;line-height:16px;font-family:Arial,sans-serif;coloration:#ffffff;"> |
2 |
® Somebody, Someplace 2021<br/><a href="http://www.instance.com" type="coloration:#ffffff;text-decoration:underline;">Unsubscribe</a> |
3 |
</p>
|
And on our social media icons, we’ll type every hyperlink to be white, in order that if the pictures do not load, any alt textual content will likely be seen on the crimson background. Regulate every hyperlink in order that they appear like this:
1 |
<a href="http://www.twitter.com/" type="coloration:#ffffff;"> |
and
1 |
<a href="http://www.fb.com/" type="coloration:#ffffff;"> |



And there now we have it! Every part is in.
7. Run Some Exams
At this level, it is a good suggestion to run your HTML code by way of an electronic mail testing service like Litmus, or E-mail on Acid. Leaving the borders on all of the tables and cells will be useful to see what’s occurring in every electronic mail shopper. (Relying on how you’re testing your electronic mail, you would possibly must remotely host your photographs first, and insert the complete distant URLs for every picture into your code. Seek advice from your testing service’s web site to learn to check your HTML.)
Listed here are a few of my check outcomes from E-mail on Acid:



Now it is time to flip off the borders and see the e-mail design trying stunning. Within the type
tag within the head
, take away the road that reads:
1 |
desk, td {border:2px strong #000000 !necessary;} |



And that’s it!
You’ve Created a Easy HTML E-mail!
Earlier than we name it a day, in case you have used any feedback in your CSS within the head of your file for any motive, do away with them. Some electronic mail purchasers can choke on CSS feedback so it’s wisest to not embody them.
Now is an efficient time to do a ultimate check with Litmus, or E-mail on Acid, after which your HTML electronic mail is able to ship!
Be taught Extra About HTML E-mail
To take what you’ve discovered to the following stage! Try our Mastering HTML E-mail studying information for extra tutorials on HTML electronic mail templates, electronic mail design, coding responsive electronic mail, accessibility, advertising and marketing, transactional electronic mail, electronic mail service suppliers (ESPs), growth workflow ideas, and extra!