How to layout a letter so that it reaches the recipient as intended

Hello! My name is Egor Steblin, I am a front-end developer in the special projects department at KTS.

In the article I will tell you and show you how to layout a letter so that it is certainly displayed correctly in all email clients – especially in Outlook, which still tops the list of popularity in the Russian Federation.

What will be in the article

Why do we need email newsletters?

Email newsletter has one of the best ROI among digital marketing channels – approximately 36:1.

Mailing allows you to establish the closest possible contact with representatives of your target audience. After all, in it you can contact the user by name and make a personal offer. Here's what else newsletters do:

  • retain active customers and return those who have already ceased to be them

  • encourage customers to make repeat purchases

  • encourage customers to make impulse purchases

Now let’s imagine: your potential or already active client opens a letter that has come from you, and in it there is a floating layout, half-loaded fonts and pictures, and at the bottom there is an inscription “open in a separate window”, cutting off half of the letter. Awkward, isn't it?

Our article will help you make a letter without errors.

Why type out letters manually?

Typesetting letters by hand is a non-standard task. The last time I needed this was to insert email code inside a wrapper that was being developed by other developers.

But if you don’t have specific requirements, and many subtleties scare you, we recommend trying ready-made solutions that will take everything into account for you – for example, mosaico.io.

What could go wrong

According to caniemail.comthe support rating for all available HTML and CSS elements for email layout looks like this:

  • Apple Mail (iOS and MacOS) – 93%

  • Mail.ru (desktop version) – 67%

  • Outlook (iOS and MacOS) – 63-65%

  • Google Mail – from 37 to 52% depending on the platform

  • Other versions of Outlook – from 19 to 61% depending on the platform

Support for accessible HTML and CSS elements in other clients

For this article, we have collected letter layout methods that we have tried and tested from our own experience and that definitely work. We'll tell you why you need to use tabular layout, what the problem is with Outlook, and where to check emails for support.

Outlook problem

Full version

In short: Microsoft Outlook supports only from 19 to 65% of the available layout and at the same time is still very common in the Russian Federation. There is a new version, but it is not yet known what elements it supports. Therefore, if potential readers of your letters use Outlook, to be on the safe side, you should use all the rules below.

Basic principles

Use table layout. When Outlook switched to rendering through Microsoft Word, many CSS and HTML features were no longer available. The most stable development path was tabular layout – and remains so to this day.

The new Outlook almost completely supports div development, but many users still use older versions of the client. Perhaps in 2-3 years the majority will switch to the new Outlook, and then the tables will become less relevant – but for now.

Maximum size of a document containing a letter — 100 Kb. Images and fonts loaded from outside do not count. There are several reasons for this:

The maximum width is 800 pixels. Previously, due to Outlook and average screen sizes, the standard of 600 pixels was used. Today the maximum width has increased to 800 pixels. If you do it even wider, a number of problems may arise, from the appearance of horizontal scrolling to incorrect rendering.

Maximum letter width for mobile devices — 400 pixels. Without prescribed styles, the email client itself will compress the letter to fit the screen, maintaining the proportions.

Use only inline styles, because they are supported by most of the customers. The style tag is not supported everywhere. For example, the Google email client accepts styles inside the style tag only in emails from Google accounts. If you link a Yandex client to Google mail, then in letters from Yandex mail the styles in the style tag will not reach the client at all. And style-styles can simply be lost during shipment.

To speed up development, you can use CSS classes. But before rolling out to production, use a service that will wrap everything inline, for example templates.mailchimp.

Check element and property support. You can use the service caniemail.com: each HTML element, attribute, CSS property is tested on 20-30 email clients at once, for each of which a version is written that supports a specific element. If the support is incomplete or has bugs, caniemail will tell you what exactly is not working.

As for the content of the letter itself, of course, the basic elements are available to you:

  • Text

  • Images

  • Links

Unfortunately, video and audio are not supported in most email clients at the moment, but you can use a CSS modifier to add interactivity :hover which applies certain styles when hovering over any element.

Be careful!  You can only add this modifier through the use of CSS classes.  Accordingly, it is subject to all potential problems associated with the<style> tag.” title=”Be careful!  You can only add this modifier through the use of CSS classes.  Accordingly, it is subject to all potential problems associated with the</p>
<style> tag.

Be careful! You can only add this modifier through the use of CSS classes. Accordingly, it is subject to all potential problems associated with the tag <style>.

You can use services to test sending emails putsmail.com, mailtrap.io emailonacid.com. We use putsmail.com.

To get started, simply paste the HTML code into the editor and click “Send Email.”

Layout in HTML

Preheader. This is the email subheading that appears next to the header:

The text in bold is the header, followed by the preheader in gray text.  See how often it gets cut?  Therefore, the shorter, the more reliable.

The text in bold is the header, followed by the preheader in gray text. See how often it gets cut? Therefore, the shorter, the more reliable.

The user sees the preheader before opening. He can repeat the text in the letter, or he can briefly summarize it. In general, the recommended length for a preheader is between 30-80 characters. But don’t forget that clients are different and everything needs to be tested beforehand.

Since the preheader can show up to the first 150 non-code characters, after it the main body of the letter may suddenly appear. To avoid this, you need to fill the empty space with a sequence of special characters ending with a space (one such sequence is equal to one space on the client) “&#8199;&#65279;&#847; 

In any case, it is better to hide the preheader in the body of the letter so as not to duplicate information that the recipient has already seen. Quite a few styles are hung for this purpose to hide for sure.

To hide the preheader we use the following settings:

<div
  style="
    font-size: 0px;
    color: #ffffff;
    line-height: 1px;
    mso-line-height-rule: exactly;
    display: none;
    max-width: 0px;
    max-height: 0px;
    opacity: 0;
    overflow: hidden;
    mso-hide: all;
  "
>
    Текст прехедера
</div>

For all tables (

), you need to forcefully remove the default styles. This is necessary for identical playback on all clients if any of them applies styles:

border="0" 
cellspacing="0"
cellpadding="0" 
role="presentation"
  • border="0" sets the border thickness of table cells to 0 pixels, thus removing borders and lines between cells

  • cellspacing="0" sets the distance between table cells to 0 pixels and removes the spaces between cells

  • cellpadding="0" sets the padding in table cells to 0 pixels. Like cellspacing, it helps remove indentation

  • role="presentation" allows screen readers to display only the contents of the table without indicating which cell it is in

For all images, enter alt and border=”0”.

  • alt is intended to provide alternative text for an image. Used if the user has disabled image loading or has visual limitations

<img src="https://habr.com/ru/companies/kts/articles/798615/example.jpg" alt="Описание изображения">
  • border is a required attribute for identical rendering on all clients, because some email clients can automatically add borders to images

<img src="https://habr.com/ru/companies/kts/articles/798615/example.jpg" alt="Описание изображения" border="0">

All links require a title. First of all necessary for the same reason as the attribute alt from the previous section: if the email recipient uses a screen reader, title will give information about the link.

<a style="text-decoration: none" href="https://kts.tech/" title="Join us">

More title can trigger tooltips on mouseover, providing users with additional information about the link. But remember that not all email clients and browsers support and display tooltips the same way.

For alignment use valign and align. They are designed to control the vertical and horizontal alignment of the contents of table cells, respectively. They apply to tags <td> (table cell) or <th> (cell title).

<td valign="top">Содержимое ячейки</td>
<td align="center">Содержимое ячейки</td>

Example

source - caniemail.com

Layout in CSS

Use pixels and percentages as units of measurement, since among the units of measurement they have the greatest support, and:

If we take into account only new clients with a high level of support for CSS functionality, then relative units can also be used. But we act for sure, so we expect to make a letter that even the old version of Outlook will draw, so we don’t take this option.

Immediately type out the rubber. For all key elements of the letter, which should occupy 100% of the width, you need to specify the maximum width through the max-width property. This can help avoid display issues on devices with very wide screens.

Media queries for responsiveness are supported in only 50% of email clients. Therefore, it is necessary to calculate from the very beginning how each element will fill the space.

Avoid styles like position: absolute. There are a number of properties that are only supported in the most advanced clients, such as Apple Mail. Absolute positioning of elements is one of them.

Only table properties can be used for positioning valign And align — and experiment with indentations using padding And margin.

Write styles in full. Clients may not support shorthand styles at all—or may not perceive them in the way the developer expects. That's why:

Use padding on parent components instead of margin on child ones. Padding has a lot of support, so this way you will reduce the number of possible bugs.

Background-image can only be used as a last resort. It's supported in modern clients, but versions of Outlook before 2023 won't understand what it is. If the use of background-image is critical, it is better to reconsider the entire solution and implement some alternative, for example, try background-color.

Fonts

Use email-safe fonts. They are available on the vast majority of devices, and therefore in the email clients installed on them, so their use is safe. The likelihood that the client will fully support another font is 24%.

Another reason to use email-safe fonts: while custom fonts are loading, the text in the letter is not displayed.

The integration code for an email-safe font may differ from the integration code for a custom font in an email. The connection might look something like this:

body {
    font-family: Arial, sans-serif;
  }

In the case of custom fonts in web development, the rule is often used @font-face for loading fonts. It defines a custom font and its sources - paths to font files, formats and other parameters. For example:

@font-face {
    font-family: "CustomFont";
    src: url("path/to/custom-font.woff2") format("woff2");
  }

  body {
    font-family: "CustomFont", Arial, sans-serif;
  }

But not all email clients support loading fonts using @font-face. Therefore, if a custom font is critical, be sure to write a full fallback to the email-safe font:

body {
    font-family: "CustomFont", "FallbackFont", Arial, sans-serif;
  }

Here “FallbackFont” - email-safe font. If “CustomFont” is not available, the browser or email client will look for the next font in the list.

Phantom tables

If there is some block with a width specified in percentage and a limitation in the form max-widthin 100% of cases Outlook will skip the restriction because it simply does not know the property max-width. As a result, defects in the layout may appear.

An example of such defects:

Desired letter structure

Desired letter structure

Result of erroneous rendering in Outlook

Result of erroneous rendering in Outlook

But if you wrap table elements in a comment, it will be perceived only in desktop Outlook versions 2007-2019 due to the engine. Others simply won’t see these commented tables, hence the name.

Therefore, all divs and tables with variable widths, especially for Outlook, should be wrapped in a phantom table with a static width:

<!--[if mso | IE]>
    <table
    role="presentation"
    border="0"
    cellpadding="0"
    cellspacing="0"
    width="600"
    style="width: 600px"
  >
    <tr>
      <td>
    <![endif]-->
        <div style="width: 100%; max-width: 600px; margin: 0 auto">
            <!-- Контент письма -->
        </div>
  <!--[if mso | IE]>
      </td>
    </tr>
  </table>
  <![endif]-->

Sample letter from start to finish

As you can see, in addition to what was stated earlier, we use certain meta tags here. We will not describe each of them in detail, but will focus only on one of the most important - viewport. This tag is responsible for scaling your document on mobile devices. The standard values ​​for it are: width=device-width And initial-scale=1 . Then the contents of the document are scaled to fit the width of the device and the zoom parameter is returned to its original position.

Sample letter from start to finish
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html
  xmlns="http://www.w3.org/1999/xhtml"
  xmlns:v="urn:schemas-microsoft-com:vml"
  xmlns:o="urn:schemas-microsoft-com:office:office"
  lang="ru"
>
  <head>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
    <meta http-equiv="X-UA-Compatible" content="IE=edge" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <title>Example</title>
  </head>

  <body
    style="margin: 0; padding: 0; min-width: 100%; background-color: #dde0e1"
  >
    <!--[if (gte mso 9)|(IE)]>
      <style type="text/css">
        body {
          background-color: #dde0e1 !important;
        }
        body,
        table,
        td,
        p,
        a {
          font-family: Arial, sans-serif, Helvetica !important;
        }
      </style>
    <![endif]-->

    <center style="width: 100%; table-layout: fixed; background-color: #dde0e1">
      <div
        style="
          max-width: 600px;
          background-color: #fafdfe;
          box-shadow: 0 0 10px rgba(0, 0, 0, 0.2);
        "
      >
        <div
          style="
            font-size: 0px;
            color: #fafdfe;
            line-height: 1px;
            mso-line-height-rule: exactly;
            display: none;
            max-width: 0px;
            max-height: 0px;
            opacity: 0;
            overflow: hidden;
            mso-hide: all;
          "
        >
          Example
          Preheader&zwnj;&nbsp;&zwnj;&nbsp;&zwnj;&nbsp;&zwnj;&nbsp;&zwnj;&nbsp;&zwnj;&nbsp;&zwnj;&nbsp;
          &zwnj;&nbsp;&zwnj;&nbsp;&zwnj;&nbsp;&zwnj;&nbsp;&zwnj;&nbsp;&zwnj;&nbsp;&zwnj;&nbsp;
          &zwnj;&nbsp;&zwnj;&nbsp;&zwnj;&nbsp;&zwnj;&nbsp;&zwnj;&nbsp;&zwnj;&nbsp;&zwnj;&nbsp;
          &zwnj;&nbsp;&zwnj;&nbsp;&zwnj;&nbsp;&zwnj;&nbsp;&zwnj;&nbsp;&zwnj;&nbsp;&zwnj;&nbsp;
          &zwnj;&nbsp;&zwnj;&nbsp;&zwnj;&nbsp;&zwnj;&nbsp;&zwnj;&nbsp;&zwnj;&nbsp;&zwnj;&nbsp;
          &zwnj;&nbsp;&zwnj;&nbsp;&zwnj;&nbsp;&zwnj;&nbsp;&zwnj;&nbsp;&zwnj;&nbsp;&zwnj;&nbsp;
          &zwnj;&nbsp;&zwnj;&nbsp;&zwnj;&nbsp;&zwnj;&nbsp;&zwnj;&nbsp;&zwnj;&nbsp;&zwnj;&nbsp;
          &zwnj;&nbsp;&zwnj;&nbsp;&zwnj;&nbsp;&zwnj;&nbsp;&zwnj;&nbsp;&zwnj;&nbsp;&zwnj;&nbsp;
          &zwnj;&nbsp;&zwnj;&nbsp;&zwnj;&nbsp;&zwnj;&nbsp;&zwnj;&nbsp;&zwnj;&nbsp;&zwnj;&nbsp;
          &zwnj;&nbsp;&zwnj;&nbsp;&zwnj;&nbsp;&zwnj;&nbsp;&zwnj;&nbsp;&zwnj;&nbsp;&zwnj;&nbsp;
          &zwnj;&nbsp;&zwnj;&nbsp;&zwnj;&nbsp;&zwnj;&nbsp;&zwnj;&nbsp;&zwnj;&nbsp;&zwnj;&nbsp;
        </div>

        <!--[if (gte mso 9)|(IE)]>
        <table width="600" align="center" border="0" cellspacing="0" cellpadding="0" role="presentation"
          style="color:#1C1E23;">
        <tr>
        <td>
      <![endif]-->
        <table
          align="center"
          border="0"
          cellspacing="0"
          cellpadding="0"
          role="presentation"
          style="
            color: #1c1e23;
            background-color: #fafdfe;
            font-family: Arial, Helvetica;
            margin: 0;
            padding: 0;
            width: 100%;
            max-width: 600px;
            padding: 40px 0 40px 0;
          "
        >
          <tr align="center">
            <td>
              <h1 style="margin: 0">Hello world</h1>
            </td>
          </tr>
          <tr>
            <td style="padding: 20px 0 0 0" align="center">
              <table
                border="0"
                cellspacing="0"
                cellpadding="0"
                role="presentation"
                style="max-width: 400px"
              >
                <tr>
                  <td>
                    <img
                      src="https://habr.com/ru/companies/kts/articles/798615/./example.jpeg"
                      alt="example"
                      border="0"
                      width="100%"
                    />
                  </td>
                </tr>
              </table>
            </td>
          </tr>
          <tr>
            <td>
              <table
                border="0"
                cellspacing="0"
                cellpadding="0"
                role="presentation"
                style="width: 100%"
              >
                <tr>
                  <td style="padding: 20px 0 0 40px">
                    <h2 style="margin: 0">Hello world but smaller</h2>
                  </td>
                </tr>
                <tr>
                  <td style="padding: 20px 0 0 40px">
                    <p>Become a part of hello world community for just $9.99</p>
                  </td>
                </tr>
              </table>
            </td>
          </tr>
          <tr>
            <td align="center" style="padding: 30px 0 0 0">
              <table
                border="0"
                cellspacing="0"
                cellpadding="0"
                role="presentation"
                style="
                  border-spacing: 0;
                  mso-cellspacing: 0;
                  mso-padding-alt: 0;
                "
              >
                <tr>
                  <td
                    style="
                      padding: 20px 20px 20px 20px;
                      background: #0d4cd3;
                      border-radius: 10px;
                    "
                  >
                    <a
                      href="https://kts.tech/"
                      target="_blank"
                      style="
                        text-align: center;
                        text-decoration: none;
                        color: #e8fbfa;
                      "
                      title="Join Us"
                      >&nbsp;&nbsp;Join Us&nbsp;&nbsp;
                    </a>
                  </td>
                </tr>
              </table>
            </td>
          </tr>
        </table>
        <!--[if (gte mso 9)|(IE)]>
        </td>
        </tr>
        </table>
      <![endif]-->
      </div>
    </center>
  </body>
</html>

Conclusion

Our approach to email layout may seem a little strange: despite modern technology development, even Gmail supports a little more than half of all HTML and CSS features, not to mention Outlook. All this is reminiscent of the postman Pechkin, who lives in 2024 and still delivers letters on a bicycle, just to be sure.

In fact, new clients with high element support are already in use, they just haven’t replaced the old ones yet. Therefore, for now we have to focus on legacy.

And when the approaches change, we will definitely write a new version of the article and tell you about the new layout rules - stay tuned!


Other articles about frontend for beginners:

Other articles about frontend for advanced:

Similar Posts

Leave a Reply

Your email address will not be published. Required fields are marked *