When it comes to building emails that can work well for both mobile and desktop, you might want to have a design that features two or three column layouts for desktop, but be a one column layout on mobile. To accomplish this and have it work across all clients, several things are required. Below are all the required actions including steps for ensuring that Outlook app for Windows behaves.
- Create a class to be placed in a media query style in the <head> styles that will reset the width of your table columns to be the full width of the parent table.
- Create an Outlook only style tag that will be paired with Outlook comments. More on this later.
- The <td> that will hold the multiple tables needs to have the width attribute and width, min-width, max-width styles applied to it with the same value as the parent <table>. The <td> should also have
align="left"
applied to account for Apple Mail 5 and Outlook 2011 running on Mac OS X 10.7 Lion. If the left alignment is not set, the tables will stack for desktop in those (probably used by two people) clients.
- Each table that gets created to be a column should have the following set along with other expected attributes for tables:
align="left"
, width="Y=(parentTableWidth / numColumns)"
, class="mobile_width_600"
, style="width:Ypx; min-width:Ypx; max-width:Ypx; display:block;"
. The display:block
style is used to cover off on older versions of Firefox.
- Add an Outlook-only comment in between each table that adds <td> tags to get around Outlook adding space when there are multiple tables side-by-side.
Now let's dive into each step. The following set of examples will assume a content width of 600 pixels and that there are two "columns" to be shown.
First we have to create the width reset class for mobile devices. Featured is the media query I use for emails to cover off on iOS and stock Android email clients. Also being used is the CSS selector that, in this example, finds all tables with a class attribute thats value is set to "mobile_width_600" and applies the new width to it. The "!important" part is required to overrule the inline style.
@media only screen and (min-device-width:240px) and (max-device-width:710px) {
	.mobile_width_600 {
		width:600px !important;
		min-width:600px !important;
		max-width:600px !important;
	}
}
Next up, if you care about Outlook anyway, are the Outlook only styles. Here we will be creating a brand new <style> tag surrounded with an HTML comment that Outlook will recognize as markup to insert and apply.
Now we are coming to the actual content area of the email. In the next example, we will have a full width table containing a full width column with an id attribute value of "outlookColumn" referencing the previous example's Outlook id style change. This is because we will have another Outlook comment between the two tables that wraps both the content tables with td tags to make the two "column" layout an actual two column layout for Outlook to avoid the issue of Outlook 2007 and higher adding 3 pixels of padding when two tables are placed side-by-side in the markup. Making further considerations for Outlook, valign="top"
will be applied to ensure the columns will be matched in layout positions. This can be changed of course, but because every other desktop client will actually be using tables as columns, you can't guarantee any vertical alignment other than "top" unless you add a height value to the tables and the inner columns. Following previous best practices mentioned, width attributes and styles will be applied to cover off on both Gmail's and Outlook's rendering issues.
<table border="0" cellpadding="0" cellspacing="0" width="600" style="width:600px; min-width:600px; max-width:600px;">
	<tr>
		<td id="outlookColumn" align="left" valign="top" width="600" style="width:600px; min-width:600px; max-width:600px;">
			<table align="left" border="0" cellpadding="0" cellspacing="0" width="300" class="mobile_width_600" style="width:300px; min-width:300px; max-width:300px; display:block;">
				<tr>
					<td align="center">
						Left/top column content goes here
					</td>
				</tr>
			</table>
		
			<table align="left" border="0" cellpadding="0" cellspacing="0" width="300" class="mobile_width_600" style="width:300px; min-width:300px; max-width:300px; display:block;">
				<tr>
					<td align="center">
						Right/bottom column content goes here
					</td>
				</tr>
			</table>
		</td>
	<tr>
</table>
Now if you want to get clever and have left column desktop be the bottom column on mobile, you can. You just need to flip the tables so that the "left" column table comes second in the markup and has align="left"
. Then the "right" table, written first in the markup, has align="right"
set on the table. When the tables have enough space to sit side-by-side, they will honor the alignment regardless of the order they are written in, but when there is not enough space for both tables that causes them to stack, they will stack in order they are written in the markup.
Sadly the one downside to this is that you have to remove the Outlook comment in between the two tables as well as the id="outlookColumn"
from the containing column, otherwise the two tables will still have the first table written be on the left. Because of having to remove the Outlook-only markup and styles, you have to worry about Outlook adding 3 pixels of invisible space between the two tables. So if you care about Outlook correctly displaying the layout like every other client, you will need to reduce the size of the tables by at least 3 pixels between the two. The following example will take two pixels off each table.
<table border="0" cellpadding="0" cellspacing="0" width="600" style="width:600px; min-width:600px; max-width:600px;">
	<tr>
		<td align="left" valign="top" width="600" style="width:600px; min-width:600px; max-width:600px;">
			<table align="right" border="0" cellpadding="0" cellspacing="0" width="298" class="mobile_width_600" style="width:298px; min-width:298px; max-width:298px; display:block;">
				<tr>
					<td align="center">
						Right/top column content goes here
					</td>
				</tr>
			</table>
			<table align="left" border="0" cellpadding="0" cellspacing="0" width="298" class="mobile_width_600" style="width:298px; min-width:298px; max-width:298px; display:block;">
				<tr>
					<td align="center">
						Left/bottom column content goes here
					</td>
				</tr>
			</table>
		</td>
	<tr>
</table>