HTML email layouts are built with tables and inline CSS because email clients, unlike web browsers, strip, rewrite or ignore much of the code they receive. Table-based structure positions content consistently, including in desktop Outlook, which uses a word-processor engine for layout. Inline styles survive clients that remove the style block from the head. Modern CSS layout such as flexbox and grid is unevenly supported in email clients, so tables remain the dependable foundation.
This guide shows how to structure a table layout, what to inline and what to leave in a style block, how to automate inlining, and a checklist covering markup, images, links, accessibility and message size. Client support changes, so confirm any property against a current reference such as caniemail.com.
Why tables and inline CSS persist
| Problem in email clients | Consequence | Table and inline approach |
|---|---|---|
| Style block removed or altered by some clients | Unstyled content | Inline styles on elements |
| Word engine in classic Outlook | Floats, margins and positioning fail | Table cells with explicit widths and padding |
| Class and selector support varies | Rules not applied | Direct style attributes |
| JavaScript and forms are blocked or stripped | No dynamic behaviour | Use links and server-side logic |
| Different default margins and fonts | Inconsistent spacing | Explicit resets on every element |
None of this prevents you from using a modern workflow. Write components in a readable format, then compile to table-based, inlined HTML as a build step. The output is for email clients, not for human editing.
A reliable table structure
Use a full-width outer table for background colour, and inside it a centred container table of 600 pixels or less. Add rows for header, hero, body and footer. Where you need columns, nest another table inside a cell. Set role="presentation" so screen readers do not announce layout tables as data, and reset cellpadding, cellspacing and border.
<table role="presentation" width="100%" cellpadding="0" cellspacing="0" border="0" style="background:#f4f4f4;">
<tr>
<td align="center" style="padding:24px 12px;">
<table role="presentation" width="600" cellpadding="0" cellspacing="0" border="0" style="width:600px;max-width:100%;background:#ffffff;">
<tr>
<td style="padding:24px;font-family:Arial,Helvetica,sans-serif;font-size:16px;line-height:24px;color:#222222;">
<h1 style="margin:0 0 12px 0;font-size:24px;line-height:30px;">Order shipped</h1>
<p style="margin:0 0 16px 0;">Your parcel is on its way.</p>
<table role="presentation" cellpadding="0" cellspacing="0" border="0">
<tr>
<td bgcolor="#0b5fff" style="border-radius:4px;">
<a href="https://example.com/track" style="display:inline-block;padding:12px 24px;font-family:Arial,sans-serif;font-size:16px;color:#ffffff;text-decoration:none;">Track parcel</a>
</td>
</tr>
</table>
</td>
</tr>
</table>
</td>
</tr>
</table>The button is a table cell with a background colour, with the link inside, a common pattern that works widely. Classic Outlook ignores padding on the link, so for full fidelity use the VML approach in Outlook HTML email rendering.
What to inline and what to keep in a style block
- Inline: font family, size, colour, line height, margins, padding, background colour, borders, widths and text alignment.
- Style block in the head: media queries, hover states and resets that are enhancements. Clients that remove the block lose only the enhancement.
- Attributes alongside CSS:
width,height,align,valignandbgcoloron tables and cells help older engines. - Avoid: CSS variables, advanced selectors, external stylesheets, shorthand that some clients mishandle and unsupported units.
- Always set: an explicit font stack on every text-bearing cell, since inheritance is unreliable in some clients.
The properties supported by each client are tabulated in email CSS support. Responsive techniques are in responsive email design.
Automating CSS inlining
Hand-inlining is error-prone. Keep your styles in a normal stylesheet or style block while developing and inline them in a build step. Several libraries do this; Premailer for Python and Juice for Node.js are widely used. The example uses Premailer.
# pip install premailer
from premailer import transform
source = '''
<html><head><style>
p { margin:0 0 16px 0; font-family:Arial,sans-serif; color:#222; }
.btn { background:#0b5fff; color:#fff; padding:12px 24px; }
</style></head>
<body><p>Hello</p><a class="btn" href="https://example.com">Open</a></body></html>
'''
inlined = transform(source, keep_style_tags=True, remove_classes=False)
print(inlined)Check the output rather than trusting it blindly. Inliners can drop rules inside media queries (which is why they usually preserve the style block) or fail on unusual selectors. After inlining, send real test messages as explained in creating and testing HTML email templates.
Markup, images and links
- Use a doctype,
langattribute andmeta charsetUTF-8, so characters display correctly. - Give each image
width,height,altandstyle="display:block;border:0;". Write meaningful alt text, since many clients block images by default. See blocked images. - Host images on a reliable HTTPS domain; avoid embedding large data URIs, which many clients do not support.
- Make link text descriptive and use full HTTPS URLs. Avoid link shorteners.
- Include a plain-text alternative that carries the same message.
- Add an unsubscribe link and your postal address where required in marketing email.
- Keep a sensible balance of text and images; see text to image ratio.
Common structural patterns
| Pattern | How to build it | Note |
|---|---|---|
| Two columns | A table with two cells of fixed width, or the hybrid inline-block technique | Stack on mobile with a media query or hybrid code |
| Image beside text | Nested table with an image cell and a text cell | Set vertical alignment on both cells |
| Spacer | A cell with explicit height and a non-breaking space or line-height:1px | Prefer padding on cells over spacer images |
| Divider | A cell with a top border or a thin coloured cell | Avoid hr styling, which varies |
| Footer | A final row with address, preferences and unsubscribe links | Required for marketing email in many regions |
Treat each section as a self-contained module: a row with its own padding, background and fonts. Modules can then be reordered or removed without breaking neighbours, which is exactly what editors and template systems need. Keep the number of nested levels as low as practical; every extra table adds weight and a chance for a client to misinterpret spacing. For a ready-made approach to repeating sections, header and footer content, see creating and testing HTML email templates.
Naming matters for maintainability. Use consistent comments to mark the start and end of each module in the source, and strip them from the production build to save bytes. Keep brand colours and font stacks in variables in your source files and compile them into the inlined output, so a rebrand is a single change followed by a rebuild and a test round, instead of a search across hand-edited markup.
Accessibility and size
Accessible email is also more robust email. Use semantic headings inside the table cells, sufficient colour contrast, a logical reading order that makes sense when read top to bottom and a language attribute. Avoid text in images alone. For more, see accessible HTML email.
Message size matters: Gmail clips the display of messages over about 102 KB of HTML, hiding the rest behind a link, which can hide your footer and unsubscribe link and remove tracking. Keep HTML lean, strip comments from the production build and avoid duplicating inlined declarations unnecessarily. Check the final size of the compiled file before sending.
Best-practice checklist
- 600 px or narrower container, centred, with a fluid fallback.
- Nested tables,
role="presentation", no layout reliance on margins on divs. - Inline styles on every element that needs them, with a resilient font stack.
- Media queries in the head only as enhancement.
- Images with dimensions and alt text; no critical content in images only.
- A plain-text part and a web version link.
- Total HTML size well under the clipping threshold.
- Tested on real clients, in dark mode and with images off.
Troubleshooting
| Symptom | Likely cause | Fix |
|---|---|---|
| Styles missing in some clients | Style block stripped | Inline critical styles |
| Unexpected gaps between images | Inline image baseline spacing | display:block on images |
| Columns collapse oddly | Nested table widths not set | Set widths on tables and cells |
| Footer cut off in Gmail | HTML over the clipping limit | Reduce size; remove unused CSS and comments |
| Inliner removed responsive rules | Rules inside media queries | Keep the style block and test the output |
| Odd characters | Wrong charset | Declare UTF-8 in the head and the MIME header |
Send your finished templates Deliver tested HTML email through an SMTP relay or API.
References and further reading
Frequently asked questions
Why do HTML emails still use tables?
Table layout renders consistently across email clients, including classic Outlook, where modern CSS layout is unreliable.
Do I need to inline CSS?
Yes for critical styles, because some clients strip or ignore the style block. Keep media queries and enhancements in the head.
How do I inline CSS automatically?
Use a tool such as Premailer for Python or Juice for Node.js as a build step, then check the output in real clients.
How wide should an email be?
A 600 px container is the common maximum, with fluid behaviour on smaller screens.
Why was my email footer cut off in Gmail?
Gmail clips displayed messages above roughly 102 KB of HTML. Reduce markup and unused CSS.