Sub topic 2
Structuring a template with tables
This chapter assumes you know basic HTML and CSS and the box model. It also assumes you have read the previous chapter on why email clients restrict HTML. Here you build the skeleton that every later chapter adds to.
Why tables still matter
Many email clients, including desktop Outlook, handle div positioning, floats, flexbox, and grid unreliably or not at all. Tables render the same way in nearly all of them. For that reason, email layout uses tables for structure and keeps CSS for styling only.
These tables describe layout, not data. Mark each one with role='presentation' so screen readers don't announce rows and columns.
The two-layer pattern
Most templates use two nested tables:
- The outer table is 100% wide and carries the page background color. One centered cell holds the content.
- The inner table is the container. It has a fixed maximum width, usually 600px, and a white or light background.
A minimal skeleton
<!DOCTYPE html>
<html lang='en'>
<head>
<meta charset='utf-8'>
<meta name='viewport' content='width=device-width, initial-scale=1'>
<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'>
<table role='presentation' width='600' cellpadding='0' cellspacing='0' border='0' style='width:100%;max-width:600px;background-color:#ffffff;'>
<tr>
<td style='padding:24px;font-family:Arial,Helvetica,sans-serif;font-size:16px;line-height:24px;color:#222222;'>Hello, your order is confirmed.</td>
</tr>
</table>
</td>
</tr>
</table>
</body>
</html>What each attribute does
| Piece | Purpose |
|---|---|
| `width='100%'` on the outer table | Fills the viewport so the background color spans the screen |
| `align='center'` on the outer cell | Centers the container without relying on `margin:auto` |
| `width='600'` plus `max-width:600px` | Gives older clients a fixed width and lets modern clients shrink it |
| `cellpadding='0' cellspacing='0' border='0'` | Removes default spacing that clients add differently |
| `style='padding:24px'` on `td` | Creates space inside a cell; padding is more dependable on `td` than on `div` or `table` |
Rules for reliable tables
- Put spacing in
tdpadding. Margins on tables and paragraphs are inconsistent across clients. - Set text styles (font, size, color) on each
td, because inheritance is unreliable. - Use
valign='top'on cells in multi-column rows so content aligns at the top. - Keep the structure simple. Each extra nesting level adds code and a chance for a client to render it differently.
Common errors
- Missing
role='presentation', which makes screen readers read the layout as a data table. - Setting
width='600'as the only width, so the layout never scales down. - Using
marginfor spacing and finding it ignored in some clients. - Leaving out
cellspacing='0', which produces thin unexplained gaps between cells. - Forgetting the closing
</td>or</tr>. Browsers forgive this, but email clients may not, and the layout breaks unpredictably.
Exercise
A colleague's template has a 600px container table with only width='600' set. On a 375px-wide phone, the email can be panned sideways. What do you change on the container table, and why does it work?
Show answer
Add style='width:100%;max-width:600px;' and keep the width='600' attribute as a fallback. The inline width:100% lets the table shrink to the screen, while max-width:600px stops it from growing wider than 600px on desktop. Clients that ignore max-width still receive the fixed attribute.