Sub topic 11
Outlook fallbacks with conditional comments
This chapter assumes you know basic HTML and CSS, the box model, and how the fluid layout from the earlier chapters works. You should also know that email clients render HTML with very different engines.
Why Outlook needs special handling
Desktop Outlook on Windows (2007 to 2019, and Microsoft 365 builds that still use the same engine) renders email with Microsoft Word, not a browser. Word ignores several CSS properties that fluid layouts rely on. The most important one for this tutorial is max-width on div elements. Without it, a div that was meant to stop at 600px stretches across the whole window.
The fix is to give Outlook a fixed-width table to use and give every other client the fluid div. You do this with conditional comments, a Microsoft-only syntax that other clients treat as ordinary HTML comments.
How conditional comments work
Outlook's Word engine reads the content inside <!--[if mso]> ... <![endif]-->. Every other client sees a comment and skips it. mso stands for Microsoft Office.
The pattern is to open a table inside one comment, put the fluid content in the middle, and close the table inside a second comment.
<!--[if mso]>
<table role='presentation' align='center' width='600' cellpadding='0' cellspacing='0' border='0'><tr><td>
<![endif]-->
<div style='max-width:600px;margin:0 auto;'>
Content that scales down on phones
</div>
<!--[if mso]>
</td></tr></table>
<![endif]-->Outlook sees a 600px centered table that holds the content. Gmail, Apple Mail, and phone clients see only the div, which shrinks below 600px.
Targeting versions and excluding Outlook
You can also target versions or exclude Outlook. The syntax is below.
| Syntax | Who sees the content |
|---|---|
| `<!--[if mso]>` | All Word-engine Outlook versions |
| `<!--[if gte mso 12]>` | Outlook 2007 and later |
| `<!--[if !mso]><!-->` ... `<!--<![endif]-->` | Everyone except Word-engine Outlook |
The third form is useful when a block contains markup that Word handles badly, such as a modern CSS feature. Note the unusual closing comment, which differs from the first two.
Other Outlook-only fixes
Conditional comments are not the only tool. Two smaller fixes are common:
mso-hide:allin an inline style hides an element in Outlook. The preheader chapter uses it.- A
<td>withbgcolorplus padding keeps buttons and blocks stable, because Word handles table cells far better than paddeddivoraelements.
Keep these fixes small. Each one adds markup that only one client reads, and you will need to test it separately.
Common errors
- Unbalanced comments. If the closing
<![endif]-->is missing, Outlook may swallow the rest of the email, or other clients may show a stray tag. Check that every opener has a matching closer. - Stripped comments. Some email tools and minifiers remove HTML comments, and that breaks the fallback. Check your build output, not only the source.
- Putting
msoblocks inside the wrong element. A table opened in one place and closed in another must produce valid nesting once the comments are removed. Read the Outlook version of the HTML on its own to check this. - Assuming new Outlook behaves the same. The newer Outlook for Windows and Outlook on the web use browser engines and ignore
msocomments, so they use the fluiddiv. This is fine, because they supportmax-width.
Exercise
A fluid div with max-width:600px stretches to the full window in desktop Outlook. Which markup makes Outlook use a 600px container without changing what Gmail renders, and why does Gmail not show the table?
Show answer
Wrap the div in a table opened inside <!--[if mso]> ... <![endif]--> and closed in a second <!--[if mso]> ... <![endif]--> block. Word-engine Outlook reads the table and gets a fixed 600px container. Gmail treats both blocks as ordinary HTML comments and ignores them, so it renders only the fluid div.
Exercise
What conditional comment would show a block to every client except Word-engine Outlook?
Show answer
<!--[if !mso]><!--> before the block and <!--<![endif]--> after it.