HTML technical guidelines
Specifications for a successful email
When creating a newsletter or email campaign directly in HTML, it is useful to know the specifications required to ensure that the content is displayed correctly in most email clients and services, such as Outlook and Gmail, and on different devices.
These specifications are based on the many years of experience gained by Contactlab staff and on the countless deliveries sent by clients.
Objective
The technical specifications for creating high-quality HTML to use with the Contactlab Marketing Cloud Send module.
General rule
The HTML code of an email must be “simpler and cleaner” than the HTML of a web page. Webmail services and email clients have difficulty managing certain elements, such as stylesheets and JavaScript, that browsers can handle more easily.
The following specifications also identify the elements that should not be included in a message to help avoid display problems for recipients.
What is important to know
The following sections describe the main technical requirements for creating HTML emails that are displayed correctly in different email clients and on different devices.
They cover the recommended structure, HTML elements, styles, images, links, message size, and elements to avoid.
Content layout
All message content must be inserted into a fixed-width table, with the width specified in the width attribute of the <table> tag. The width must also be specified for each cell, for example, <td width="121">.
Recommended width
The table described in the Content layout section must have a fixed width, but there is no absolute maximum size. However, it is preferable not to exceed 600–650 px to avoid inconvenient horizontal scrolling for recipients.
Recommended length
There is no recommended length. However, newsletters and marketing emails should not be too long. As much detail as possible should be provided on web pages, with the relevant links included in the message.
Doctype
To ensure that the HTML of the newsletter is interpreted correctly, use the following doctype:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<title> tag in the <head>
Insert text in the <title> tag. Avoid leaving the default text assigned by the HTML editor, such as “Untitled1” or “New Page 1”. It is preferable for the title to match the email subject.
Bugfix in the head
To ensure correct display and prevent text resizing on mobile devices or in Outlook due to zoom, include the following code in the <head> tag:
<!--[if gte mso 9]>
<xml>
<o:OfficeDocumentSettings>
<o:AllowPNG/>
<o:PixelsPerInch>96</o:PixelsPerInch>
</o:OfficeDocumentSettings>
</xml>
<![endif]-->
<style type="text/css">@-ms-viewport{width:device-width}</style>
<style type="text/css">
html { -webkit-text-size-adjust:none;}
body, .ReadMsgBody, .ExternalClass, .multi-col .column {width: 100%; width:100% !important; margin: 0px !important; padding: 0px; display: block; -ms-overflow-style: none !important;}
.ExternalClass {line-height: 100%;}
table, tr, td {margin:0; padding: 0; border-collapse: collapse !important; mso-line-height-alt:0px; mso-margin-top-alt:0px; mso-table-lspace:0px; mso-table-rspace:0px; vertical-align: top; border-spacing: 0; }
td { font-size:0px; line-height: 0px; }
a img, img{margin: 0px; padding: 0px; display: block;}
</style>
Meta tags
To ensure that characters, including those in any online version, are displayed correctly and to add information to social shares on Facebook, include the following meta tags in the <head> tag:
<meta http-equiv="content-type" content="text/html; charset=UTF-8">
<meta property="og:title" content="TITLE" />
<meta property="og:description" content="DESCRIPTION" />
<meta property="og:image" content="IMAGE URL" />
Stylesheets use
Stylesheets (CSS) should be used sparingly, as follows:
- Do not use CSS to define the position of an element, such as the alignment of an image or table, padding, float, or similar properties.
- In the message HTML, CSS can be inserted:
- internally, in the
<head>tag; - inline, in the cells and within the
<link>and<div>tags where the class is called.
- internally, in the
CSS attributes commonly used in newsletters
- Background-color (BACKGROUND COLOR): hexadecimal color code, for example,
#ff0000. - Background-image: URL (
IMAGE PATH): background image. - Color (TEXT COLOR): hexadecimal color code, for example,
#ff0000. - Text-align (HORIZONTAL TEXT ALIGNMENT): left, right, justify, or center.
- Text-decoration (UNDERLINED or NO): underline or none.
- Font-family (FONT TYPE): font name or “family” name [WEB SAFE].
- Font-size (FONT SIZE): expressed in pixels.
- Line-height (INTERLINE): expressed in pixels.
- Width (WIDTH): expressed in pixels or %.
- Height (HEIGHT): expressed in pixels or %.
- Vertical-align (VERTICAL ALIGNMENT): top, bottom, or middle.
The two stylesheets must have the same characteristics.
Body
Insert the following style in the <body> tag to ensure that the message centering is not affected by the default email client settings:
<body style="margin: 0; padding: 0px;">
Structure tags
<table>indicates the beginning of the table.<tr>indicates the beginning of a row.<td>indicates the beginning of a cell.</td>indicates the end of a cell.</tr>indicates the end of a row.</table>indicates the end of the table.
Usable newsletter attributes
- Dir (DIRECTION OF WRITING): rtl or ltr.
- Cellpadding (CELL INNER SPACE): expressed in pixels.
- Cellspacing (SPACE BETWEEN THE CELLS): expressed in pixels.
- Border (TABLE BORDER DIMENSION): expressed in pixels.
- Align (HORIZONTAL ALIGNMENT): left, right, center, or justify.
- Valign (VERTICAL ALIGNMENT): top, middle, bottom, or baseline.
- Bgcolor (BACKGROUND COLOR): hexadecimal color code, for example,
#ff0000, RGB value, or color name. - Background (BACKGROUND IMAGE): image link.
- Width: expressed in pixels or %.
- Height (HEIGHT): expressed in pixels or %.
- Colspan (NUMBER OF CELLS GROUPED IN A COLUMN): number identifying the grouped columns.
- Rowspan (NUMBER OF CELLS GROUPED IN A ROW): number identifying the grouped rows.
Tag attributes
<body>: class, dir, id, lang, style, title, bgcolor, background.<table>: align, bgcolor, background, border, cellpadding, cellspacing, width, height, class, dir, id, lang, style, title.<tr>: no attributes.<td>: align, bgcolor, background, colspan, width, height, class, dir, id, lang, nowrap, rowspan, valign, style, title.
Font
- Fonts used in newsletters must be web-safe to ensure consistent display across different operating systems. A list of safe fonts is available here.
- Font size should be defined using an absolute pixel value.
- To prevent mobile devices from modifying the font size, include the following in the internal CSS:
-webkit-text-size-adjust: none; - Always use a font size greater than 9 px and less than 23 px. Exceeding this range may increase the spam score.
- Always set the line height to at least 4 px more than the font size.
- The recommended size for readability on mobile devices is greater than 14 px.
Preheader
The preheader, also called an Eyebrow, is the first line of text in an email and allows recipients to see the main content at a glance. It is visible before the email is opened in Gmail, Outlook, and most mobile devices.
An invisible preheader that appears only in the inbox preview can be added using the following code:
<div class="preheader" style="display:none !important; visibility:hidden; opacity:0; color:transparent; height:0; width:0; color:#ffffff; font-size:1px; line-height:0; overflow:hidden; mso-hide:all;">TEXT</div>
Use the following CSS class as well:
.preheader {
display:none !important;
visibility:hidden;
opacity:0;
color:transparent;
height:0;
width:0;
color:#ffffff;
font-size:1px;
line-height:0;
overflow:hidden;
mso-hide:all;
}
<br> instead of <p>
Use the <br> tag to break lines and avoid using the <p> tag, which creates a paragraph. Each webmail service or email client applies different top and bottom margins, changing the appearance of the message.
Images
Images that are not embedded must be uploaded to a server, either Send's server or another server. The absolute path must then be inserted in the src attribute of the tag.
The format should be JPG, GIF, including animated GIFs, or PNG. The use of mapped images is strongly discouraged. Each image should be as small as possible to avoid increasing download time.
Background Images
If the HTML contains background images, avoid using white text or text in a color that matches the <body> background. Recipients who have enabled image blocking in their email client will not see the message until the images are downloaded.
Background images cannot be added through the stylesheet; they must be inserted directly into the cell.
However, where possible, avoid using background images because they may increase the risk of display issues.
For example:
<td background="http://domain.it/images/bg_main.jpg" bgcolor="#dadada" align="center" style="padding: 0px; vertical-align:top; width:600px; height: 300px;" width="600" height="300">
<!--[if gte mso 9]>
<v:rect xmlns:v="urn:schemas-microsoft-com:vml" fill="true" stroke="false" style="width:600px;height:300px;">
<v:fill type="tile" src="http://domain.it/images/bg_main.jpg"/>
<v:textbox inset="0,0,0,0">
<![endif]-->
#CONTENT
<!--[if gte mso 9]>
</v:textbox>
</v:rect>
<![endif]-->
</td>
Text-Image balance
Avoid using only images in HTML, as this greatly increases the likelihood of the message being classified as spam. It can also make emails appear empty because most webmail applications automatically block the download and display of images.
Text should therefore be used instead of images whenever possible. The suggested composition of an email is 60% text and 40% images.
Large images should be divided into two or more parts and then assembled using a table.
Image naming
Assign each image a name that reflects its content. Avoid generic names such as 001.gif, 002.gif, photo1.jpg, or photo2.jpg.
This reduces the risk of the message being classified as spam. Avoid spaces and accented letters in image names. Underscores can be used, for example, vacation_photo.jpg.
Characters
Be careful with characters generated by Word, such as quotation marks, ellipses, dashes, and apostrophes. Replace them with the corresponding keyboard characters.
Link text
Do not use the link URL as the link text. For example, avoid links such as <a href="https://www.contactlab.com/">www.contactlab.com</a>. Some widely used email programs perform anti-phishing checks that may flag these links as suspicious.
Use text instead, such as <a href="https://www.contactlab.com">Contactlab</a>.
It is also recommended to:
- insert, at the beginning of the text, an option to view the content on the web: a link to a fixed page on the server or the code
${online_version_url}$, so that all recipients can view the communication correctly; - add a reference to the Data Protection Code regarding privacy at the bottom of the communication;
- include a link at the bottom of the communication that allows recipients to unsubscribe from the newsletter.
Recommended message size
The maximum recommended HTML size is 60 KB. It is good practice not to exceed 100 KB to prevent the message from being cropped.
Elements to avoid
- Mapped images: Do not insert images containing a map. Instead, split the image and reassemble it using a table, linking the individual parts.
- JavaScript: Do not insert JavaScript into the HTML of the message.
- Flash: Do not insert Flash files (
.swf) into the HTML. If moving elements are required, use animated GIFs.