Sub topic 1
Why email HTML is different from web HTML
Prerequisites
This chapter assumes you know basic HTML and CSS, including the box model and how a media query works. You should also know that an email client is the program that opens a message, and that the sender's HTML arrives as the body of that message. You don't need any email-specific experience.
The core difference: you don't control the renderer
A web page runs in a browser you can name and test against. An email runs in whatever client the recipient uses: Gmail in a browser, the Apple Mail app, Outlook on Windows, a Samsung phone app, and many others. Each client reads your HTML and then rewrites it for its own safety and display rules.
The result is that the same markup can look different in each client. Email design is mostly the practice of writing markup that survives all of them.
What clients change or remove
Clients modify your HTML for three main reasons: security, consistency, and old rendering technology.
- Security. Clients strip or block
<script>, most<form>behavior, and embedded media. They may also block remote images until the reader allows them. - Style handling. Some clients remove or limit the
<style>block, ignore parts of CSS, or rewrite class names. Others ignore<link>tags to external stylesheets. - Rendering engines. Desktop Outlook on Windows uses Microsoft Word to draw HTML. Word does not support many modern CSS features, so
max-widthon adivand layout based onfloatorflexcan fail there.
| Feature | Typical web support | Typical email support |
|---|---|---|
| JavaScript | Full | None |
| External stylesheet | Full | Mostly ignored |
| `<style>` block | Full | Varies by client |
| Inline `style` attributes | Full | Widely supported |
| Flexbox and grid | Full | Unreliable |
| Media queries | Full | Supported in many mobile clients, not all |
| Web fonts | Full | Only in some clients |
The working model
Treat email HTML as a defensive format. Follow these rules of thumb, which later chapters cover in detail:
- Build layout with nested tables, because every client understands them.
- Put the important styles inline on each element, so they survive when a
<style>block is removed. - Use a
<style>block only for enhancements, such as media queries. The layout must still work without it. - Provide a fallback for each risky feature, such as a conditional comment for Outlook.
- Test in real clients instead of trusting a single browser preview.
A minimal example
The first snippet is a common web approach. The second is the email-safe equivalent. Both show a centered 600-pixel box with a message.
<div style="display:flex;justify-content:center;">
<div style="max-width:600px;">Hello</div>
</div><table role="presentation" width="100%" cellpadding="0" cellspacing="0" border="0">
<tr>
<td align="center">
<table role="presentation" width="600" cellpadding="0" cellspacing="0" border="0" style="width:100%;max-width:600px;">
<tr>
<td style="font-family:Arial,Helvetica,sans-serif;font-size:16px;line-height:24px;">Hello</td>
</tr>
</table>
</td>
</tr>
</table>The table version centers with the align attribute, sets the width with both an attribute and a style, and puts the font settings directly on the cell. Each choice avoids a feature that some client mishandles.
Common errors
- Designing in a browser only. A page that looks right in Chrome can break in Outlook or lose its styles in Gmail.
- Relying on the
<style>block for layout. If the client drops it, the layout collapses. - Using modern layout tools. Flexbox, grid, and floats are not dependable across clients.
- Forgetting that images may be blocked. Important content should not live only in an image.
- Assuming one phone client stands for all. Mobile clients differ as much as desktop ones.
Exercise
A teammate builds a two-column email with display:flex in a <style> block, and it looks perfect in Chrome. Give two reasons it might fail for readers, and name the technique this tutorial recommends instead.
Show answer
Some clients remove or ignore the <style> block, and many clients, including desktop Outlook, don't support flexbox reliably. The recommended approach is a table-based layout with important styles inline, using a <style> block only for enhancements such as media queries.