...

Developing HTML Emails Using Divs and “Ghost Tables”

gorilla-chimp

HTML emails have always been developed using <table> elements, and only <table> elements. Until now. The fact is, only Microsoft Outlook requires you to use tables for HTML structure; all other email and webmail clients support the use of <div>s for this purpose.

Divs have several advantages over tables. They’re more flexible to work with, supporting CSS properties that tables don’t (such as float) and unlike tables, they don’t create issues for subscribers using assistive technologies, such as screen readers.

Introducing Ghost Tables

It’s perfectly possible to develop HTML emails using tables and divs. Doing so enables you to deliver emails that render perfectly in Microsoft Outlook, and, allows you to leverage all the flexibility that divs offer. You can achieve this by transforming HTML email tables into HTML email “ghost tables” (tables that only versions of Microsoft Outlook render) and wrapping them them around divs that all email and webmail clients render.

In this tutorial, I’ll walk you through each of the essential elements, attributes, and styles necessary for developing HTML email tables. I’ll then walk you through each of the essential elements, attributes, and styles necessary for developing HTML email ghost tables, and their associated divs. However, before I do, allow me to give you some background as to why tables have to be used in the first place.

Why We Need Tables to Develop HTML Emails

Microsoft Word, released in 1983, was originally designed and developed as a word processor, a tool for creating simple text documents. Since then, Microsoft has developed it further, enabling its users to create complex text and image documents with elaborate layouts. To create a layout in Microsoft Word you have to insert a table then divide it into rows and cells to form its structure. You’re then able to populate your layout (or structure) with your content.

Microsoft Word has been built into every version of Microsoft Outlook for Windows since the release of Microsoft Outlook 2007, in the form of the Microsoft Word rendering engine. As this rendering engine is essentially “Word in Outlook”, in order to create a functional email layout you have to insert a table, just like in Microsoft Word. However, as we’re dealing with email, you need to build it with HTML and insert it by sending it via an email service provider.

“Since the release of Microsoft Outlook 2007, in 2007, all versions of Microsoft Outlook on Windows have used the Microsoft Word rendering engine.”

Microsoft Office 2007
Microsoft Outlook 2007 was part of the Microsoft Office 2007 suite.

Microsoft Outlook versions that use the Word rendering engine:

  • Microsoft Outlook 2007
  • Microsoft Outlook 2010
  • Microsoft Outlook 2013
  • Microsoft Outlook 2013 120 DPI
  • Microsoft Outlook 2016
  • Microsoft Outlook 2019
  • Windows 10 Mail

Developing HTML Email Tables

Now let’s look at the elements, attributes and styles necessary for developing an HTML email table.

Elements

An HTML email table consists of three elements:

  1. A <table> element (table)
  2. A <tr> element (table row)
  3. A <td> element (table data cell, or as it’s more commonly referred to, a table cell)

Tables may contain multiple table cells, on multiple table rows, and those table cells in turn may have tables nested within them. As such, tables are “building blocks”, which when nested within, or positioned above or below each other, form the structure of an email. The table cells that are wrapped within the tables contain the emails’ content.

Attributes

Inserted inside the opening <table> tag are the table attributes: role, cellpadding, cellspacing and border. The attributes are defined as follows:

  • role="presentation": defines the <table> as being presentational, rather than using data, preventing it from creating issues for subscribers using assistive technologies, such as screen readers.
  • cellpadding="0": removes the default cellpadding, preventing gaps appearing around the content of each table cell.
  • cellspacing="0": removes the default cellspacing, preventing gaps appearing between each each table cell.
  • border="0": removes the default borders, preventing borders from appearing in the table.

Additional attributes, such as width and align, may also be inserted inside the opening <table> and <td> tags.

Styles

Inserted inside the opening <td> tag, is the inline CSS that styles the table cell, (the <td>), and its content. The text styling will be inherited by all the paragraphs within the <td>, unless the paragraphs themselves have inline CSS overriding those styles, applied to them, inside their respective opening <p> tags. The style margin:0; is applied inside each opening <p> tag to remove the default spacing applied to paragraphs.

Developing HTML Email Ghost Tables

As HTML email ghost tables are only rendered by versions of Microsoft Outlook, you only need to take versions of Microsoft Outlook into account when developing their elements, attributes, and styles.

Elements

An HTML email ghost table consists of the same three elements as a standard HTML email table. The only difference is that its opening and closing <table>, <tr> and <td> tags are wrapped within Microsoft conditional comments

Code wrapped within Microsoft conditional comments is only rendered if the opening comment is true. In this example, the Microsoft conditional comment is <!--[if true]>, which states that if it’s true (that the email is being opened by any version of Microsoft Outlook) then the code within it should be rendered. You can configure the opening comment to render code on specific versions of Microsoft Outlook, or none at all, but that’s a whole other tutorial!

Attributes

As with HTML email tables, inserted inside the opening <table> tag are the table attributes, rolecellpaddingcellspacing and border. Additional attributes, such as width and align, may also be inserted inside the opening <table> and <td> tags.

The <div>

The <div> is inserted after the first <![endif]--> conditional comment, and before the second <!--[if true]> comment. This <div> contains the email’s content.

Styles

Two types of CSS are used to apply styling to ghost tables and divs:

  • Internal CSS, to style ghost tables, and their respective table cells.
  • Inline CSS, to style divs and their content.

Internal CSS

Internal CSS is used to style ghost tables and their respective cells. This internal CSS is wrapped within the same type of Microsoft conditional comments as those wrapped around the ghost tables and their respective cells. Styles applied here typically relate to their structure, not their content, such as their width and background-color, as in the following: 

The classes defined within the internal CSS are applied to the relevant ghost tables and cells.

Inline CSS

Inline CSS is applied to style the divs and their content, in much the same way as a <td> within a standard HTML email table. Structural styles, such as width, are not rendered by versions of Microsoft Outlook, as the divs themselves are not recognised or rendered by Microsoft Outlook. Their content, and therefore their text styles, such as font-family are, however.

Harnessing the Power of Ghost Tables

Once you’ve grasped how to work with ghost tables, and their respective table cells, you can then begin to harness the power of divs within email. I’ll conclude this tutorial by looking at one skill–the use of float. Take a look at the following:

In this example, ghost tables, cells and divs have been used to structure a left and right column. Classes have been applied to each of the <td> and <div> elements, with a class of ltr applied to the left and right divs. The internal CSS applied to them, .two_Cln_Lft_Cln_1_3.ltr {float:right !important;} and .two_Cln_Rgt_Cln_4_6.ltr {float:left !important;} respectively, switches the left column to the right, and vice-versa.

Conclusion

The implementation of ghost <table>s, <td>s and <div>s allows you to structure emails for versions of Microsoft Outlook, without being restricted by their limitations. It’s more work than you might be used to when building for the web, but the extra effort will pay off. Check your analytics to see how many users might be affected by email which their client doesn’t support.

HTML Email Template Resources on Tuts+

Discover more from WIREDGORILLA

Subscribe now to keep reading and get access to the full archive.

Continue reading