Sub topic 6
Media queries and stacking columns on phones
This chapter assumes you know how the table-based layout, inline CSS, and the viewport meta tag work from the earlier chapters. It also assumes you can read a basic CSS media query. Here you will add the one behavior that makes a multi-column email usable on a phone: columns that stack vertically when the screen is narrow.
The working model
A media query is a CSS rule that applies only when a condition is true. In email the condition is almost always the width of the screen or window. A typical rule says: when the viewport is 600 pixels wide or less, make each column fill the full width, one under another.
Media queries have to live in a <style> block in the <head>, because inline style attributes cannot contain them. That creates the central design constraint of this chapter. Some clients ignore or remove embedded style blocks, so a media query is an enhancement, never the foundation.
The reliable pattern has three layers:
- The base layout works with no embedded CSS at all. It uses a fluid container and table cells that look acceptable at any width.
- All essential styling (colors, fonts, padding) is inline.
- The media query only changes the layout on small screens, for example turning side-by-side cells into full-width blocks.
If a client drops the query, the reader sees the base layout, which is still readable, only smaller.
Which clients honor the query
Support changes over time, so treat this table as a general guide and confirm it in your own tests.
| Client | Embedded style and media queries |
|---|---|
| Apple Mail, iOS Mail | Supported |
| Gmail app and web with a Google account | Supported, within limits |
| Gmail app with a non-Google account (such as an Outlook or Yahoo address) | Not supported |
| Outlook.com, Outlook mobile apps | Generally supported |
| Samsung Mail | Partial |
| Outlook for Windows (Word engine) | Media queries ignored |
Gmail also drops the whole style block if it exceeds about 16 KB, or if it contains CSS it cannot parse. Keep the block short and use simple class selectors.
The flow below shows what happens when a client opens your message.
Stacking columns step by step
A two-column row is a single <tr> with two <td> cells. On a wide screen, table cells sit side by side. Setting display: block on a cell takes it out of table-cell behavior, so each cell takes its own line and fills the width of its parent.
The steps:
- Give each column cell a class, such as
stack. - In the media query, set
display: blockandwidth: 100%on that class. - Mark both declarations
!important.
The !important is needed because inline styles beat embedded styles in the cascade. If the cell has style='width:50%' inline, only an !important rule in the style block can override it. A width='50%' HTML attribute is weaker than any CSS rule, so it does not need !important, but the habit is harmless.
A complete example
<!DOCTYPE html>
<html lang='en'>
<head>
<meta charset='utf-8'>
<meta name='viewport' content='width=device-width, initial-scale=1'>
<title>Two columns that stack</title>
<style>
@media screen and (max-width: 600px) {
.stack {
display: block !important;
width: 100% !important;
box-sizing: border-box !important;
}
.pad-sm { padding: 16px !important; }
}
</style>
</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 class='stack pad-sm' width='50%' valign='top' style='padding:24px;font-family:Arial,Helvetica,sans-serif;font-size:16px;line-height:24px;color:#222222;'>
<strong>Shipping</strong><br>
Your order leaves the warehouse today.
</td>
<td class='stack pad-sm' width='50%' valign='top' style='padding:24px;font-family:Arial,Helvetica,sans-serif;font-size:16px;line-height:24px;color:#222222;'>
<strong>Delivery</strong><br>
Expected on Friday before 6 pm.
</td>
</tr>
</table>
</td>
</tr>
</table>
</body>
</html>Points worth noticing in this code:
- The outer container is
width='600'as an attribute for clients that need it, andwidth:100%;max-width:600pxinline so it shrinks on its own. Even without the query, the table never overflows a phone. box-sizing: border-boxmatters. A block-level cell withwidth: 100%andpadding: 24pxwould, under the default content-box model, be 48 pixels wider than its parent and cause sideways scrolling. Border-box counts the padding inside the 100%.- The
pad-smclass reduces padding to 16 pixels on phones. Without it, the 24-pixel inline padding stays, which wastes space on a 360-pixel screen.
Choosing breakpoints
A breakpoint is the width at which the layout changes. Match it to the width of your container. A 600-pixel template should stack at max-width: 600px, so the columns never get squeezed below their comfortable width.
Some teams add a second, smaller breakpoint (often 480 pixels) to shrink headline sizes or hide secondary content. Add it only when you have a concrete need, because every extra rule adds more CSS for Gmail's size limit.
Use @media screen and (max-width: 600px) rather than a bare @media (max-width: 600px). The screen keyword keeps the rule from applying when a message is printed, and it avoids a parsing problem in a few older clients.
The query measures the viewport, which depends on the viewport meta tag from the previous chapter. Without it, some mobile clients render the message at a virtual width of 980 pixels and the query never fires.
Edge cases and design choices
Source order controls stacking order
Columns stack in the order they appear in the HTML. If your design puts an image on the left and text on the right, the image appears first on a phone. That is usually fine. If you want the text first, the usual approach is to change the source order and accept that desktop will show text on the left. A trick that reverses the order with dir='rtl' on the row exists, but it complicates the text direction and often breaks in some clients, so avoid it unless you test it carefully.
Spacing between stacked cells
When two cells become blocks, they touch each other. The padding inside each cell usually keeps them apart. If your columns have no padding, add a class that sets padding-bottom on the first cell inside the media query only, so the desktop layout is not affected.
Three or more columns
Stacking works the same way for any number of cells in a row. For a grid of four items, such as product cards, a better mobile result is often two per row. That needs the cells in two separate rows or a width: 50% !important rule on the class. Keep each item self-contained so any grouping still reads well.
Showing and hiding content
Many templates hide a desktop element on phones with display: none !important inside the query. Use this sparingly. A client that ignores the query will show both versions, and a screen reader may read hidden content in some clients. If the content matters, show it on every screen.
Outlook for Windows
The Word engine ignores media queries, so Outlook desktop shows the base layout: two columns inside the fixed-width container. That is the correct result, because desktop Outlook runs on a wide window. You do not need to fix it, but you should check that the two-column version holds together without the query.
Common errors
| Symptom | Likely cause | Fix |
|---|---|---|
| Columns never stack on a phone | Inline `width` beats the rule, or the `!important` is missing | Add `!important` to `display` and `width` in the query |
| Stacked layout scrolls sideways | Padding added to a 100% width with content-box sizing | Add `box-sizing: border-box` |
| Query works in Apple Mail, not in Gmail | Style block over the size limit or containing invalid CSS | Shorten the block and simplify selectors |
| Layout is tiny and unstacked on some phones | Missing viewport meta tag | Add `width=device-width, initial-scale=1` |
| Stacking works in the browser preview, not in the real client | Gmail with a non-Google account does not support embedded styles | Design the base layout to work alone |
Summary
Stacking columns is a small addition on top of a layout that already works. Put the rule in an embedded style block, give the cells a class, set display: block and width: 100% with !important, and include box-sizing: border-box so padding does not cause overflow. Match the breakpoint to the container width, and remember that several major clients will never run the query.
Exercise
A template has a row of two cells with style='width:50%;padding:20px' and class col. The media query contains .col { display: block; width: 100%; }. On an iPhone the columns stay side by side. Name the two changes that fix it, and say what happens on a phone if you add width:100% but leave out box-sizing: border-box.
Show answer
Add !important to both declarations, because the inline width:50% otherwise wins over the embedded rule. Also confirm the viewport meta tag is present so the query measures the real screen width. Without box-sizing: border-box, the 20px of padding on each side is added to the 100% width, so each cell is 40px wider than its container and the message scrolls sideways.
Exercise
Your template is opened in Gmail with a non-Google account, and the client discards the style block. Describe what the reader sees for a two-column row inside a width:100%;max-width:600px container, and what you should check in your design because of this.
Show answer
The reader sees the base layout: two columns that scale with the container, side by side and smaller on a phone, with inline styles intact. Check that the text in each column is still readable at that narrow width, that no fixed widths cause overflow, and that no essential content depends on the media query.