Sub topic 11
Outlook fallbacks with conditional comments
Desktop Outlook on Windows (versions 2007 to 2021 and Microsoft 365 classic) renders email with Microsoft Word's layout engine instead of a browser engine. Most of the layout in this tutorial works there, but a few pieces break. Conditional comments let you give Outlook its own markup while every other client sees the normal version.
This chapter assumes you have read the earlier chapters on table layout, inline CSS, and fluid hybrid layouts. You should be comfortable with max-width, display:inline-block, and nested tables.
What the Word engine gets wrong
Word is a document editor, so it handles web CSS selectively. The failures you will meet most often are listed below.
| Feature | Behavior in desktop Outlook | Fallback |
|---|---|---|
| `max-width` on a `div` | Ignored, so the div fills the window | Fixed-width table in a conditional comment |
| `border-radius` | Ignored, so corners are square | Accept square corners, or use VML |
| Padding on `<a>` | Often ignored, so the click area shrinks | Padding on a table cell, or a VML shape |
| `display:inline-block` columns | Stack or misalign | Ghost table around the columns |
| Web fonts | Ignored, and Times New Roman may appear | Force a safe font in an `mso` style block |
| Image scaling at high DPI | Images can render at the wrong size | Set `PixelsPerInch` to 96 |
| `line-height` | Can add unexpected extra space | `mso-line-height-rule:exactly` |
Not every Outlook is affected. Outlook for Mac, Outlook.com, the mobile apps, and the new Outlook for Windows use browser engines. Only classic desktop Outlook on Windows uses Word. This is why these fallbacks target one engine, not one brand.
How conditional comments work
A conditional comment is an HTML comment with a condition inside it. The Word engine reads the condition and, if it matches, renders the contents. Every other client treats the whole thing as an ordinary comment and skips it.
The condition mso means "Microsoft Office rendering". There are two patterns.
- Show only to Outlook:
<!--[if mso]> ... <![endif]--> - Hide from Outlook:
<!--[if !mso]><!--> ... <!--<![endif]-->
The second pattern looks odd because the markup has to be valid for clients that ignore conditions. The <!--> and <!-- pieces close and reopen comments so that non-Outlook clients render the contents as normal HTML.
You can also target versions with gte, lte, lt, and gt. For example, <!--[if gte mso 9]> matches Outlook 2000 and later. Most templates only need plain mso, and gte mso 9 is used for the document settings shown later.
Ghost tables for fixed-width containers
A fluid container built with max-width works in browsers but not in Word. A ghost table wraps the fluid content in a fixed-width table that only Outlook sees.
<!--[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 table with a cell. Other clients see only the div. The opening and closing halves are split into two comments, so the tags are unbalanced inside each comment. The HTML is balanced only once Outlook has assembled the pieces. Keep each pair together and indent them clearly, because a missing <![endif]--> silently breaks everything after it.
Ghost tables for hybrid columns
The hybrid layout uses two inline-block divs that wrap onto separate lines on a narrow screen. Outlook cannot place inline-block divs side by side, so you give it a table with two cells.
<!--[if mso]>
<table role="presentation" width="600" cellpadding="0" cellspacing="0" border="0"><tr><td width="300" valign="top">
<![endif]-->
<div style="display:inline-block;width:100%;max-width:300px;vertical-align:top;">
<p style="margin:0;padding:24px;font-family:Arial,Helvetica,sans-serif;font-size:16px;line-height:24px;">Left column</p>
</div>
<!--[if mso]>
</td><td width="300" valign="top">
<![endif]-->
<div style="display:inline-block;width:100%;max-width:300px;vertical-align:top;">
<p style="margin:0;padding:24px;font-family:Arial,Helvetica,sans-serif;font-size:16px;line-height:24px;">Right column</p>
</div>
<!--[if mso]>
</td></tr></table>
<![endif]-->The comment between the two divs does two jobs. For Outlook, it closes one cell and opens the next. For everyone else, it sits where the whitespace between inline-block elements would otherwise appear. Put font-size:0 on the parent container and restore the size inside the children if you see a small gap between columns in browsers.
The width attributes of the two cells must add up to the width of the outer table. If they do not, Outlook shrinks or wraps the columns.
Document settings for image scaling
Outlook on Windows can render images at the wrong size on high-DPI displays. A settings block in the <head> fixes this. It needs the Office namespaces declared on the <html> tag.
<!DOCTYPE html>
<html lang="en" xmlns:v="urn:schemas-microsoft-com:vml" xmlns:o="urn:schemas-microsoft-com:office:office">
<head>
<meta charset="utf-8">
<!--[if gte mso 9]>
<xml>
<o:OfficeDocumentSettings>
<o:AllowPNG/>
<o:PixelsPerInch>96</o:PixelsPerInch>
</o:OfficeDocumentSettings>
</xml>
<![endif]-->
<title>Order confirmation</title>
</head>
<body></body>
</html>PixelsPerInch set to 96 tells Outlook to treat one image pixel as one CSS pixel. Without it, images at 120 DPI scaling can appear much larger than intended. Declare the v namespace now even if you only add VML later, so the button below works.
Bulletproof buttons with VML
A padded link in a table cell, as built in the buttons chapter, is already tolerable in Outlook. It loses rounded corners, and in some cases the clickable area shrinks to the text. VML (Vector Markup Language) is an older Microsoft drawing format that Word understands. A VML roundrect gives Outlook a real rounded button with a full click area.
<!--[if mso]>
<v:roundrect xmlns:v="urn:schemas-microsoft-com:vml" xmlns:w="urn:schemas-microsoft-com:office:word" href="https://example.com/order" style="height:48px;v-text-anchor:middle;width:200px;" arcsize="13%" stroke="f" fillcolor="#0b5fff">
<w:anchorlock/>
<center style="color:#ffffff;font-family:Arial,Helvetica,sans-serif;font-size:16px;font-weight:bold;">View your order</center>
</v:roundrect>
<![endif]-->
<!--[if !mso]><!-->
<a href="https://example.com/order" style="display:inline-block;padding:14px 28px;background-color:#0b5fff;border-radius:6px;font-family:Arial,Helvetica,sans-serif;font-size:16px;line-height:20px;font-weight:bold;color:#ffffff;text-decoration:none;">View your order</a>
<!--<![endif]-->The !mso block matters. Without it, Outlook would render both the VML shape and the plain link, and you would see two buttons.
The VML button has fixed width and height, so longer button text can overflow it. Size the shape for the longest translation you plan to send. For a simple call to action in a single language, many teams skip VML and accept square corners. That choice reduces the amount of Outlook-only code you must maintain.
Outlook-only styles
You can also hide a small style block from every client except Outlook. This is the safest place for rules that would be harmful elsewhere.
<!--[if mso]>
<style>
td, th, p, a { font-family: Arial, Helvetica, sans-serif !important; }
p { mso-line-height-rule: exactly; }
</style>
<![endif]-->The font rule stops Outlook from falling back to Times New Roman when your first font is a web font it cannot load. mso-line-height-rule:exactly makes Outlook respect your stated line-height and stops it from adding extra space.
Common errors
- Unbalanced comments. The opening
<!--[if mso]>has no matching<![endif]-->, so Outlook or other clients lose everything after it. - Missing the
!msopattern. Adding VML without hiding the standard link gives Outlook two buttons. - Cell widths that do not add up. Ghost table columns wider than the container wrap onto separate lines.
- Forgetting the namespaces. VML shapes and document settings need
xmlns:vandxmlns:oon the<html>tag in many setups. - Testing only in a browser. A browser preview cannot show Word-engine behavior, so you need a real Outlook or a rendering service.
- Relying on
msoto detect new Outlook. The new Outlook for Windows does not use Word, so it ignores these blocks and renders your standard markup.
Exercise
Your template has a fluid div with max-width:600px. In classic Outlook for Windows it stretches across the whole window. Which fix do you apply, and why does it not affect Gmail or Apple Mail?
Show answer
Wrap the div in a ghost table: put <!--[if mso]><table role="presentation" align="center" width="600" cellpadding="0" cellspacing="0" border="0"><tr><td><![endif]--> before it and <!--[if mso]></td></tr></table><![endif]--> after it. Classic Outlook uses the Word engine, which ignores max-width on divs but reads mso conditional comments, so it renders the fixed 600px table. Gmail and Apple Mail treat the conditional comments as ordinary comments, skip them, and use the fluid div.
Exercise
You add a VML button but forget the <!--[if !mso]><!--> wrapper around the standard link. What do Outlook users see, and what do other clients see?
Show answer
Outlook users see two buttons, the VML shape and the plain link, because Outlook renders both. Other clients see only the plain link, because they ignore the mso comment that holds the VML. Wrapping the link in <!--[if !mso]><!--> and <!--<![endif]--> hides it from Outlook.