Sub topic 1
Why email HTML is different from web HTML
This chapter explains the rendering constraints that shape every later technique in the tutorial. It covers why you build email with tables and inline styles, where clients disagree, and which mistakes follow from treating email like a web page.
Prerequisites
This chapter assumes you already know:
- Basic HTML and CSS, including the box model and the syntax of a media query.
- What an email client is, and that a message is delivered as HTML in a MIME part rather than loaded from a URL.
You do not need any email-specific experience. You do not need to send anything to follow along.
The core difference: you do not control the renderer
A web page runs in a browser you can name, and you can test against a small set of engines (Blink, WebKit, Gecko) that follow the same standards. An email runs inside whatever the recipient uses. That could be Gmail in a browser, the Gmail app, Apple Mail, Outlook for Windows, Outlook for Mac, Yahoo Mail, Samsung Mail, or a corporate webmail system.
Each client does three things before your HTML reaches the screen:
- It sanitizes the markup. Sanitizing means removing elements and attributes the client considers unsafe, such as
<script>,<form>in many clients, and event handlers likeonclick. - It rewrites the CSS. Some clients strip or rename classes, drop unsupported properties, or discard whole style blocks.
- It renders the result with its own engine. The engine may be a modern browser engine, or something much older.
The result is that valid, standards-compliant HTML can look correct in one client and broken in another. You design for the lowest common behavior, then add improvements for clients that support them.
The Outlook problem
Outlook for Windows (the desktop versions based on Outlook 2007 through 2019, and Microsoft 365 desktop builds that still use the same engine) renders HTML with Microsoft Word's layout engine, not a browser engine. This is the most important single fact in email development.
Word's engine has these consequences:
- It ignores
max-widthondivelements. - It handles
marginandpaddingunevenly, and padding on some elements is ignored. - It does not support
display: flexordisplay: grid. - It does not reliably support background images on arbitrary elements.
- It adds extra spacing in some table and paragraph situations.
Because of this, you will see later in the tutorial that Outlook gets its own fallback code, wrapped in conditional comments only Outlook reads. For now, the lesson is that you cannot assume a CSS feature works because it works in Chrome.
What a typical client supports
Support varies by feature and changes over time, so treat the table as a general guide and confirm current details with a compatibility reference such as Can I email... before relying on a feature.
| Feature | Safe to rely on? | Notes |
|---|---|---|
| Tables for layout | Yes | Works everywhere, including Outlook |
| Inline `style` attributes | Yes | The most reliable way to style |
| `<style>` block in `<head>` | Mostly | Some clients strip it, or ignore it in certain cases |
| Media queries | Mostly | Supported by Apple Mail, many Gmail setups, iOS Mail; not by every client |
| `max-width` on `div` | Mostly | Ignored by desktop Outlook |
| Flexbox and grid | No | Unsupported or partly supported |
| External stylesheets | No | Commonly blocked |
| JavaScript | No | Removed everywhere |
| Web fonts | Partly | Apple Mail supports them; many clients fall back |
The practical rule: put essential layout and appearance in tables and inline styles. Treat everything else as an enhancement that can fail without breaking the message.
Why tables still do the layout work
In web development, tables for layout were abandoned long ago in favor of CSS. In email, they remain the dependable choice, because every client, including the Word engine, interprets <table>, <tr>, and <td> consistently.
A minimal table-based structure looks like this:
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<title>Order confirmation</title>
</head>
<body style="margin:0;padding:0;background-color:#f4f4f4;">
<table role="presentation" width="100%" cellpadding="0" cellspacing="0" border="0">
<tr>
<td align="center" style="padding:24px;font-family:Arial,Helvetica,sans-serif;font-size:16px;line-height:24px;color:#222222;">
Hello from a table cell.
</td>
</tr>
</table>
</body>
</html>Three details matter here:
role="presentation"tells assistive technology that the table is for layout and not data. Without it, a screen reader may announce rows and columns.cellpadding="0",cellspacing="0", andborder="0"are attributes, not CSS, because they set a known baseline in every client. Without them, clients apply their own defaults.- Spacing goes on the
<td>as padding, since padding on table cells is handled more consistently than margin on other elements.
The next chapter covers table structure in detail.
Why styles go inline
On the web, you put CSS in a stylesheet and reference it with classes. In email, some clients remove the <style> block, or remove it when the message is forwarded or when the account type does not support it. If your layout depends on that block, it falls apart.
So the dependable pattern has two layers:
- Inline styles carry everything essential: font, size, color, padding, background.
- A
<style>block adds enhancements, such as media queries, only for clients that keep it.
A common workflow is to write readable CSS during development and run an inliner as a build step. Many email frameworks and tools do this automatically. The output keeps the media queries in the head and copies all other rules into style attributes.
<style>
@media screen and (max-width: 600px) {
.stack { display: block !important; width: 100% !important; }
}
</style>The !important flag is needed here because inline styles have higher specificity than a rule in a style block. Without it, your media query would lose to the inline width.
Common errors from thinking in web terms
These are the mistakes that appear most often when web developers write their first template.
- Relying on an external stylesheet. The link is blocked or the file is not fetched, so the message shows unstyled.
- Using
divand CSS floats for columns. Outlook and some other clients collapse or misalign them. - Setting width only with CSS on a
div. Desktop Outlook ignoresmax-width, so the layout stretches to the full window. - Assuming images load. Many clients block images until the user allows them, so a design built from a single big image shows nothing useful.
- Using shorthand and modern CSS freely. Features like CSS variables,
calc(), andpositionmay be stripped or ignored. - Testing only in a browser. A browser preview shows how a browser renders the file, which tells you very little about how an email client will.
- Forgetting the
langattribute and<title>. These matter for accessibility and for how some clients present the message.
Design principles that follow from the constraints
The constraints lead to a short list of working principles that the rest of the tutorial builds on:
- Default to a single column. One column works with no media query at all, so clients that ignore CSS still get a readable message.
- Make the base experience work without enhancements. Layout, color, and text should hold up with only tables and inline styles.
- Layer improvements on top. Add media queries, dark mode rules, and web fonts as optional upgrades.
- Keep the structure simple. Deep nesting and many tricks multiply the number of places a client can fail.
- Keep the message useful with images off. Use real text for the content, and give each image alt text.
- Test in real clients. Compatibility knowledge goes out of date, so real previews are the only reliable check.
This approach is often called progressive enhancement. The base layer is the safe one, and every enhancement is allowed to fail.
How this connects to the rest of the tutorial
Each later chapter answers a specific problem raised here:
- Table structure gives a consistent layout skeleton.
- Inline CSS and the style block define what is essential and what is optional.
- The viewport tag and resets reduce each client's default differences.
- Fluid and hybrid layouts handle width without depending on media queries.
- Media queries add column stacking where clients support them.
- Outlook fallbacks, dark mode, accessibility, and testing close the remaining gaps.
Summary of the working model
Email HTML is a sanitized, rewritten, and inconsistently rendered subset of web HTML. Tables and inline styles are the dependable base. Media queries, modern CSS, and web fonts are enhancements. Desktop Outlook uses the Word engine, so it needs special handling. A browser preview cannot stand in for a real client.
Exercise
A colleague builds a two-column email using div elements with float: left and sets the container with max-width: 600px on a div. It looks correct in Chrome. Name two clients or situations where it may break, and say what you would change.
Show answer
In desktop Outlook for Windows, the Word engine ignores max-width on div, so the container stretches to the full window. Floats may also collapse or misalign there. Clients that strip or ignore parts of the CSS can break the layout as well. Replace the div structure with a table-based layout (<table role="presentation"> with <td> cells) and put the essential styles inline. Add a conditional-comment table wrapper for Outlook if you want a fixed 600px container, and test in real clients rather than only a browser.
Exercise
Why does a media query rule in a <style> block often need !important when the same property is also set inline?
Show answer
A style set in an inline style attribute has higher specificity than a rule in a <style> block, so the inline value wins. Adding !important to the media query rule lets it override the inline value in clients that support the query.
Exercise
Give two reasons why a template should still be readable when its <style> block is removed.
Show answer
Some clients strip or ignore the <style> block, for example on certain account types or when a message is forwarded. Also, the essential layout and appearance should not depend on an optional enhancement. Putting font, color, padding, and width inline means the message still reads correctly without the block.