Sub topic 5
Fluid and hybrid layouts that scale to the screen
This chapter assumes you know basic HTML and CSS, the box model, and how table-based email structure works from the earlier chapters. It covers how to make a template resize to the screen without depending on media queries, and where that approach breaks.
Why layouts need to scale without media queries
Media queries are the usual way to adapt a page to a narrow screen. In email they are unreliable. Some clients strip the <style> block. Some ignore queries. Gmail's non-Google account support (GANGA) has historically been the common example. A template that only becomes mobile-friendly inside a media query is broken on those clients.
The fix is to make the base layout flexible first, then treat media queries as an enhancement. There are three approaches.
| Approach | How it adapts | Main weakness |
|---|---|---|
| Fixed | One width, such as 600px, on every screen | Phones zoom out or scroll sideways |
| Fluid | Widths in percentages, so it fills the screen | Gets too wide on desktop unless capped |
| Hybrid | Fluid widths capped with `max-width`, plus fallbacks for Outlook | More markup, and Outlook needs special handling |
Most production templates use the hybrid approach.
Fluid layouts
A fluid layout sizes containers as a percentage of the available width. The outer table is width="100%", so it always matches the viewport. The inner container uses a percentage too.
<table role="presentation" width="100%" cellpadding="0" cellspacing="0" border="0">
<tr>
<td align="center" style="padding:0 16px;">
<table role="presentation" width="100%" cellpadding="0" cellspacing="0" border="0">
<tr>
<td style="font-family:Arial,Helvetica,sans-serif;font-size:16px;line-height:24px;">
This content always fills the available width.
</td>
</tr>
</table>
</td>
</tr>
</table>This works on a phone. On a 1920px monitor the text line stretches across the whole screen and becomes hard to read. A fluid layout needs an upper limit.
Hybrid layouts with max-width
The hybrid technique sets a fixed width and a max-width together, as in the order confirmation template from the topic's first example:
<table role="presentation" width="600" cellpadding="0" cellspacing="0" border="0"
style="width:100%;max-width:600px;background-color:#ffffff;">Two things happen here:
- The
width="600"attribute gives clients that ignore CSS a fixed 600px table. - The inline
width:100%overrides that attribute in clients that read CSS, andmax-width:600pxstops the table growing past 600px.
On a 375px phone the table is 375px wide. On a desktop it stops at 600px. No media query is involved.
A common width cap is 600px. Values between 560px and 640px are also used. The cap keeps lines at a readable length and fits the preview pane in many desktop clients.
Adding gutters
If the table is 100% wide, text touches the screen edge on a phone. Put padding on the cells, not on the table. Padding on a <table> element is not supported consistently. A 16px to 24px cell padding gives a gutter.
<td style="padding:24px 16px;">Body copy</td>Remember that percentage widths on a cell are measured against the content box in most clients, so padding is added on top in some engines and subtracted in others. Keep padding in the outer cell and leave inner percentage cells without padding where you can. This avoids columns that overflow by a few pixels.
The Outlook problem
Desktop Outlook for Windows (2007 to 2019, and the classic Outlook 365 builds) renders HTML with the Word engine. Word does not support max-width on <div> or on tables. Without a fallback, the layout expands to fill a wide window.
The fix is a conditional comment. Only Outlook's Word engine reads <!--[if mso]>. Other clients treat it as an ordinary comment and skip it. The comment wraps a fixed-width table around the fluid content.
<!--[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]-->Read it in two parts:
- Outlook sees an opening 600px table, a plain
<div>it treats as a block, and a closing table. The result is a fixed 600px column. - Other clients ignore both comments and use the
<div>withmax-width, which scales down on phones.
The opening and closing comments must always be paired. If you forget the closing comment, Outlook gets an unclosed table and the layout breaks in confusing ways. The rest of the Outlook fallbacks are covered in a later chapter.
Hybrid columns without media queries
The same idea can build multi-column layouts that stack on their own. Each column is an inline-block <div> with a max-width. When the container is too narrow for two columns, the second one wraps below the first.
<table role="presentation" width="100%" cellpadding="0" cellspacing="0" border="0">
<tr>
<td align="center" style="font-size:0;">
<!--[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;">
<table role="presentation" width="100%" cellpadding="0" cellspacing="0" border="0">
<tr>
<td style="padding:16px;font-family:Arial,Helvetica,sans-serif;font-size:16px;line-height:24px;">Left column</td>
</tr>
</table>
</div>
<!--[if mso]>
</td><td width="300" valign="top">
<![endif]-->
<div style="display:inline-block;width:100%;max-width:300px;vertical-align:top;">
<table role="presentation" width="100%" cellpadding="0" cellspacing="0" border="0">
<tr>
<td style="padding:16px;font-family:Arial,Helvetica,sans-serif;font-size:16px;line-height:24px;">Right column</td>
</tr>
</table>
</div>
<!--[if mso]>
</td></tr></table>
<![endif]-->
</td>
</tr>
</table>Here is how it works:
- Each
<div>is at most 300px wide, so two fit in a 600px container. - Below 600px, the container cannot hold two 300px divs on one line. The second wraps and takes the full width, up to 300px.
font-size:0on the parent removes the whitespace gap that inline-block elements create between them. Set the real font size on the inner cells, as the example does.- The Outlook comments turn the two divs into two table cells, because Word does not honor
inline-block.
The trade-off
Without a media query, the stacked columns are 300px wide and centered when the screen is between 300px and 600px. On a 480px screen you get a 300px column with space on each side, not a full-width column. The width:100% helps only when the screen is narrower than 300px. If you want full-width stacked columns at 480px, you need a media query such as the one in the first topic example, which is why the two techniques are combined in practice.
Common errors
- Setting only
max-width. Withoutwidth:100%, a table or div shrinks to its content in some clients and may not fill the container. - Using
widthin CSS only. Clients that strip styles lose the width. Keep the HTMLwidthattribute as a fallback on tables. - Padding on the table. Move padding to the cells.
- Unmatched conditional comments. Each
<!--[if mso]>needs a matching<![endif]-->, and the table tags inside must balance across the whole pattern. - Whitespace between inline-block columns. A small gap pushes the second column onto a new line even when there is room. Use
font-size:0on the parent, or remove the whitespace. - Fixed pixel widths on images. An image wider than its container overflows on phones. Image handling is covered in a later chapter.
- Assuming the viewport meta tag fixes layout. It tells mobile clients not to zoom out, but it does not change how wide your content is.
Choosing between fluid, hybrid, and responsive
| Situation | Suggested approach |
|---|---|
| Single-column message such as a receipt or password reset | Hybrid single column; media queries optional |
| Multi-column layout with a large Outlook audience | Hybrid with inline-block columns and mso tables |
| Audience with no Outlook desktop users | Hybrid without mso wrappers, to reduce markup |
| Full-width stacking at specific breakpoints | Hybrid base plus a media query for the stacking |
Single-column designs are the lowest-risk choice for mobile. They need no stacking logic, and the hybrid wrapper with the Outlook fallback is the only special case.
Putting it together
The base layout should read well with every optional feature removed. Check it in this order:
- Remove the
<style>block. The layout should still be a readable column. - View it in a 320px-wide window. Nothing should scroll sideways.
- View it in a 1200px-wide window. The content should stop at the cap and stay centered.
- View it in Windows Outlook. The width should be fixed at 600px.
Exercise
A hybrid container uses <table width="600" style="width:100%;max-width:600px;">. A reader opens the email on a 400px-wide phone in a client that supports inline CSS, and then in desktop Outlook with a 1200px-wide window and no conditional-comment fallback. What width does the table have in each case, and why?
Show answer
On the phone the table is 400px wide: the inline width:100% overrides the width="600" attribute, and 100% of 400px is below the 600px cap. In desktop Outlook the Word engine does not honor max-width, so the result is not reliably capped at 600px. The table may stretch toward the window width. A conditional-comment wrapper with a fixed 600px table gives Outlook the cap that it needs.
Exercise
Two inline-block divs, each width:100%;max-width:300px, sit in a parent. The parent is 700px wide, but the second div still drops onto a second line. Name one likely cause and the fix.
Show answer
Whitespace between the two inline-block elements renders as a gap of a few pixels, which can push the total width over the available space. Setting font-size:0 on the parent (and restoring the font size on the inner cells) removes the gap. Also check that the parent has no padding that reduces the available width below 600px.