Sergey Leschev
Responsive Email Design
Swift (L6+) | Full Stack (L6+) | Design Patterns (L6+) | System Architect (L7+) | Blog
Google Engineering Level: L6+
Design large-scale systems / 2022
đ Awards
Ranking #Dev: Global TOP 200 (Certificate)
Languages: Swift, TypeScript, Shell, Database (T-SQL, PL/SQL, MySQL), Concurrency (Python3).
Algorithms: linked lists, binary search, hash table, queue/stack, dfs/bfs, sort, heap/hash, two pointers, sliding window, tree, greedy problems etc.
Golden Award for the Year of the Tiger Challenge
Algorithmic skills: Dynamic programming, Greedy algorithms, Catepillar method, Binary search algorithm, Fibonacci numbers, Euclidean algorithm, Sieve of Eratosthenes, Prime and composite numbers, Maximum slice problem, Stack and Queues, Sorting, Time Complexity, Arrays, Prefix Sums, Leader, etc.
Contest: Algorithms, SQL, Data Structures, Bitwise operations (bit-ops), Frontend.
đ Which mobile devices can you design for
A quick caveat: The techniques listed here arenât universally supported by all mobile email clients. As you may know, not all email clients were made equalâeven on the same device, how an HTML email displays can vary radically from inbox to inbox.
Thankfully, the iPhone and other Apple iOS devices can not only boast of near trouble-free email rendering, but also account for a large percentage of mobile email opens, too. However, with the latest release of iOS 13, Appleâs dark mode will pose new design and coding challenges to overcome so always remember to test your emails.
With this in mind, we present to you a non-exhaustive list of mobile email clients and their support for media queries. For context, media query support enables you to use many of the responsive techniques that weâll be covering in this guide.
Default device email clients
Client | Media query support |
---|---|
Amazon Kindle Fire | Yes |
Amazon Kindle Fire HD | Yes |
Android 2.1 Eclair | No |
Android 4.x native client | Yes |
Apple iOS | Yes |
Gmail App for Android | Yes |
Gmail App for iOS | Yes |
Yahoo Android and iOS | Yes |
Outlook Android and iOS | Yes |
Gmail Android IMAP | No |
Microsoft Windows Phone 7.5 | Yes |
Microsoft Windows Phone 8 | No |
Microsoft Surface | No |
Windows Mail | Yes |
Samsung Email 6x | No |
3rd-party email clients
Client | Media query support |
---|---|
Microsoft Outlook Exchange third-party app (Android) | No |
Gmail mobile app (all platforms). There are limitations: see supported CSS properties | Yes |
Yahoo! Mail mobile app (all platforms) | No |
đ« Design techniques for mobile optimization
Weâll be designing two CSS layouts of the same newsletter: one layout that looks great in webmail and desktop clients, and another layout that can be easily read on the smaller mobile device screens.
For example, hereâs an HTML email in Outlook:
Below is the same email, only this time viewed in Appleâs iPhone Mail. As you can see, there are significant differences between the two layouts. The mobile version is skinnier, lacks visual clutter, and is just as readable as the desktop version. This can be attributed to the use of mobile-specific CSS:
As a point of comparison, the right image is the same email, without this stylesheet. See how tiny and unreadable the text is? This is the problem that faces millions of email newsletters received on mobile devices every day.
Mobile-friendly layouts and design elements
Designing for mobile isnât simply a matter of taking a crack at writing mobile-specific CSS. Here are some other considerations:
-
Single-column layouts that are no wider than 600 to 640 pixels work best on mobile devices. Theyâre easier to read, and if they fall apart, theyâll do so more gracefully.
-
Links and buttons should have a minimum target area of 44 Ă 44 pixels, as per Apple guidelines. Nothing is more unusable than clouds of tiny links on touchscreen devices.
-
The minimum font size displayed on iPhones is 13 pixels. Keep this in mind when styling text, because anything smaller will be upscaled and could break your layout. Alternately, you can override this behavior in your style sheetâdo so with care.
-
Remember to keep your message concise, and place all important design elements in the upper portion of the email if possible. However, since screen sizes have become larger and thereâs more real estate than ever before, itâs recommended that you explore and test various formats (e.g. long-form content vs. short-form content). Always keep your brand in mind. What might work for one brand may not work for yours.
-
When appropriate, you can use mobilehide{ display: none !important;} to hide content in your mobile layout. Use caution when hiding content in mobile. Ask yourself, if your content is not worth showing in mobile, should it be included in your desktop version? If you find your design uses this class on several elements, you may want to reconsider your design and content.
When mocking up an HTML email or template, our advice is to create three sketches or wireframes: one of the desktop and webmail layout, one for the tablet layout, and one for a mobile layout. Building these three layouts will allow you to see how your content will break on various devices, and it will help determine what media queries youâll need.
đ§ Coding mobile emails
When web designers or developers talk about stylesheets or CSS (Cascading Style Sheets, theyâre usually referring to an external stylesheet. And while that works for websites itâs not the best for email.
Several major email clients block external stylesheets we included our CSS in two ways:
-
Embedded styles located in the âheadâ of an email contained in a style tag
-
Inline styles included in the body of your email
When coding a mobile-responsive email, youâll need both, as some clients will remove the embedded CSS in the âheadâ of your HTML document, so the inline style ensures your emails look perfect no matter what device your subscriber is using.
Hereâs what a basic stylesheet using both embedded and inline styles looks like:
Embedded styles
<head>
<style type="text/css">
/* regular CSS styles go here */
@media only screen and (max-device-width: 640px) {
/* tablet-larger phone CSS styles go here */
}
@media only screen and (max-device-width: 479px) {
/* smaller-mobile-specific CSS styles go here */
}
</style>
</head>
Inline styles
<table width="640" border="0" cellpadding="0" cellspacing="0">
<tr>
<td>
<table width="320" border="0" cellspacing="0" cellpadding="20" align="left" >
<tr>
<td width="320" style="font-family: Helvetica, Arial, 'sans-serif'; font-size: 33px; color:#1B1B1B; padding-left: 30px; padding-right: 30px; font-weight: 500; line-height: 40px; letter-spacing:.5px; width: 600px;">Content Example</td>
</tr>
</table>
Embedded styles are what help you create mobile-responsive layouts. In the example above, an @media declaration is made following mobile-specific CSS styles.
Letâs examine what this declaration does: @media only screen specifies that the email has to be displayed on a screen, and the second part, max-device-width states the deviceâs viewport requirements.
The examples above states that the viewport can have a maximum width of 640px and 479px, and then the styles following are implemented into your email, adjusting everything from image and text sizes to the overall layout of your email. Including two breakpoints can help you tweak various elements in your email to accommodate larger mobile displays, such as those on tablet devices.
Inline styles are the safety net of CSS, as many email clients will strip away âstyleâ tags from the âheadâ of your html email. With inline styles, you can use various properties such as setting the width, font size and weight, or font family. In the above example, we identified the table widths and created a style= in the âtdâ that declares the font, padding, and color properties.
For a more exhaustive list of what will work in your mobile-friendly email templates, I recommend visiting caniemail.com or you can use our CSS inliner tool that will take the hard work out of inlining all your styles.
Now, itâs time to revisit our earlier example of an email layout thatâs been ânarrowed downâ and stacked for a mobile display. Hereâs the design in iPhone Xs:
In this example, weâve applied the tablescale class to HTML tables containing the text and images. Below is a snippet of code that contains two @media queries, creating two breakpoints for mobile devices:
<style type="text/css">
/* regular CSS styles go here */
@media only screen and (max-width: 640px) {
/* mobile-specific CSS styles go here */
.tablescale {
width: 440px !important;
margin: 0 !important;
}
}
@media only screen and (max-width: 479px) {
/* mobile-specific CSS styles go here */
.tablescale {
width: 100% !important;
margin: 0 !important;
}
}
</style>
The tablescale class does something really interesting here. When the email is viewed on a device with a screen width of 640px or wider, it has no effect. However, when the screen width is 640px or less, it narrows down the table widths to 440px. This same action is taken at the second breakpoint at 479px, giving the table a width of 100%.
Weâve also added !important; to the mobile-specific styles to ensure they take precedence. But otherwise, itâs run-of-the-mill CSS.
You could also feature other declarations, like:
<style type="text/css">
@media only screen and (max-device-width: 640px) {
/* mobile-specific CSS styles go here */
.tablescale { width: 440px !important; margin: }
.imgscale { width: 100% !important; }
}
@media only screen and (max-device-width: 479px) {
/* mobile-specific CSS styles go here */
.tablescale { width: 325px !important; margin: 0 !important; }
.imgscale {
width: 100% !important;
height: auto !important;
margin: auto !important;
}
}
</style>
Assuming that the examples in this guide have made sense so far, weâre going to start looking at more advanced techniques for adapting your email for mobile devices.
đ« Building responsive layouts
While one-column HTML email layouts are generally the way to go when optimizing your newsletter for mobile devices, thereâs an elegant way to create responsive two-column layouts, without resorting to mile-long stylesheets in media queries.
While two-column layouts often allow more content to be featured above the fold on desktop email clients like Outlook, theyâre a pain to read and navigate on mobile devices. Fortunately, this can be fixed with a bit of coding.
One of the golden rules of email design is âwhere possible, use HTML attributes instead of CSSâ. Whereas CSS support can be fairly flaky across the gamut of email clients, attributes tend to be rock solid. For example, attributes like align=âleftâ and cellpadding=â10â are far more reliable than their approximate CSS equivalents, float: left; and padding: 10px;. Itâs exactly these attributes weâll be using when building our two-to-one column layout.
Letâs look at such a layout in Outlook 2007:
In the example above, we have a 640px-wide container table, with two 300px-wide tables nested inside to form columns, similar to our previous examples. These nested columns have cellpadding=â10âł applied to stop the content from pressing hard against the edges.
When coding for the web, weâd generally apply float: left; to the left-hand column, to get them sitting side-by-side. But in email, instead we can use align=âleftâ. As long as the container table width is more than or equal to the combined width of the two columns, both will fit nicely in this fashion.
Hereâs the simplified code for the two-column layout so far:
<table width="640" border="0" cellpadding="0" cellspacing="0">
<tr>
<td>
<table width="300" border="0" cellspacing="0" cellpadding="10" align="left">
<tr>
<td>Column Left Content</td>
</tr>
</table>
<table width="300" border="0" cellspacing="0" cellpadding="20" align="right">
<tr>
<td><img src=âIMG_URLâ width=â280â></td>
</tr>
</table>
</td>
</tr>
</table>
The rendered result:
If the container table is 640px wide, youâll get a two-column layout. But any skinnier than this and the right column will wrap under the left column. Make it the same width as the column tables (320px) and youâve got a flush, one-column layout that fits an iPhone display exactly, with no zooming required.
One-line media query to our HTML code:
<style type="text/css">
@media only screen and (max-device-width: 480px) {
.tablescale {
width:100% !important;
Margin: 0 !important;
}
}
</style>
<table width="640" border="0" cellpadding="0" cellspacing="0" class="tablescale">
The result is a responsive layout that displays two columns on desktop and web clients, then switches to one column in iPhone Mail and the default Android email client.
Adding Wikipedia-style progressive disclosure
On the web, many responsive sites convert luxurious long-form content into items compressed for mobile devices. This is typically by using a technique referred to as progressive disclosure. This involves hiding content behind an interactive element like a button or link, then displaying it on click or tap.
Wikipedia uses progressive disclosure, as do a lot of mobile applications.
Letâs say we have an email newsletter with multiple articles. In desktop email clients, we want a heading and text to display in each article, like so:
However on mobile clients, we only want the heading to display, alongside a show/hide button (which toggles the text). This turns the email into an interactive table of contents, dramatically shortening the message length:
To do this, weâll firstly need to turn to our HTML code and create an article with a heading, some text, and a show/hide button. Weâll also add a couple of classes to display the show/hide buttons exclusively on mobile devices.
Hereâs a simplified version of the code used for each of the articles:
<td>
<h4><a target="_blank" href="https://yourdomain.com" class="link">First heading</a></h4>
<a target="_blank" href="#" class="mobilehide">Hide</a> <a target="_blank" href="#" class="mobileshow">Show</a>
<div class="article">
<p class="bodytext">
<img src="https://yourdomain.com/kitten.jpg" style="float: left;" >Pellentesque habitant morbi...
</p>
<a target="_blank" href="https://yourdomain.com">Read more...</a>
</div>
</td>
Take note the classes mobilehide, mobileshow and articleâthese will be handling most of the action.
In our stylesheet, weâll hide the show/hide button when the email displays in desktop and web email clients, by using display: none; in our stylesheet like so:
.mobileshow a, .mobilehide a {
display: none !important;
}
To ensure that the show/hide buttons are only displayed on mobile devices, weâll turn to our media query. Hereâs the code, including the earlier .mobileshow and .mobilehidesnippet and some webkit-friendly button styling for good measure:
@media only screen and (max-device-width: 480px) {
.mobileshow a, .mobilehide a {
display: block !important;
color: #fff !important;
background-color: #aaa;
border-radius: 20px;
padding: 0 8px;
text-decoration: none;
font-weight: bold;
font-family: "Helvetica Neue", Helvetica, sans-serif;
font-size: 11px;
position: absolute;
top: 25px;
right: 10px;
text-align: center;
width: 40px;
}
.article {
display: none;
}
a.mobileshow:hover {
visibility: hidden;
}
.mobileshow:hover + .article, .article:hover {
display: inline !important;
}
}
And, if things go well, the result is an email with show/hide buttons that toggle content on the iPhone.
Outlook and the 120 DPI issue
Outlook continues to be widely used among many businesses, and thus should not be ignored when thinking about your responsive email design. So letâs breakdown the 120 DPI issue and how we can code around it.
DPI stands for dots per inch and is a unit of measurement for screen resolutions. Standard resolution is typically set to 96 DPI. However, with newer, higher-DPI displays, this resolution is scaled to 120 DPI.
When the DPI is scaled to 120, it will affect your text size and images, while your containers maintain their original widths, thus breaking your email. Hereâs an example without 120 DPI scaling:
And hereâs that same example with 120 DPI scaling:
This problem occurs when Microsoft Word is used to render an email, and is most common in Outlook 2007 through 2013 versions. This scaling issue continues to be a thorn in the side of many email developers and designers as this zoomed view often stretches your images, enlarges your text, and creates an overall poor user experience.
Using our previous code examples, letâs create a truly responsive template that works both in mobile and desktop.
The first step is to enable VML or Vector Markup Language, and scaled images in the âheadâ of your email.
@media only screen and (max-device-width: 480px) {
/* outlook-mso specific styles*/
<!--[if mso]>
<style type="text/css">
body, table, td {font-family: Arial, Helvetica, sans-serif !important;}
</style>
<![endif]-->
/* outlook scaled image solution */
<!--[if gte mso 9]>
<xml>
<o:OfficeDocumentSettings>
<o:AllowPNG/>
<o:PixelsPerInch>96</o:PixelsPerInch>
</o:OfficeDocumentSettings>
</xml>
<![endif]-->
The second step to fix this issue is to add inline styles to your âtablesâ and other tags such as the image tag, by re-identifying the width. A general rule of thumb, if you declare the width as anything other than 100% in a tag you should re-identify within a style.
Hereâs the code we created for our two-column layout with the added inline-styles.
<table width="640" border="0" cellpadding="0" cellspacing="0" style=âwidth: 640px;â>
<tr>
<td>
<table width="300" border="0" cellspacing="0" cellpadding="10" align="left" style=âwidth: 300px;â>
<tr>
<td width="300" align="left" style=âwidth: 300px;â>Column Left Content</td>
</tr>
</table>
<table width="300" border="0" cellspacing="0" cellpadding="20" align="right" style=âwidth: 300px;â>
<tr>
<td width="300" align="left" style=âwidth: 300px;â><img src=âIMG_URLâ width=â280â style=âdisplay: inline-block; width: 280px;â></td>
</tr>
</table>
</td>
</tr>
</table>
Now that we have that new code, hereâs the same rendering above with 120 DPI, now totally responsive with the new code additions:
The text and images are larger, but everything is now in proper alignment.
If you want to learn more about Outlook scaling issues, check out Courtney Fantinatoâs article âCorrecting Outlook DPI Scaling Issues.â
đ Targeting devices with media queries
You may have noticed that weâve been using two standard media queries in this guide: @media only screen and (max-device-width: 640px) { ⊠} and @media only screen and (max-device-width: 479px) { ⊠}. This is great for targeting Apple iPhones and other handheld devices that make up the majority of mobile email client share.
But if you or your clients want to target tablets, larger-screen Android devices, and some of the more exotic screen resolutions in the mobile ecosystem, then youâll need both unique media queries and unique styles to match.
Fine-tuning your media queries
Letâs go back to the max-device-width: 479px rule in our earlier media query. What this tells mobile email clients (and browsers) is that below the 479px threshold, a mobile-friendly layout defined therein should be displayed. Above that, CSS styles outside of the media query should be used.
But the dimensions you can design for can be even more specific than that. For example, only targeting displays that are 320px or more in width, but smaller than, or equal to 480px. Hereâs an example:
@media only screen and (min-device-width: 320px) and (max-device-width: 480px) { ... }
What a lot of folks donât know is that media queries can be quite focused. Apart from designing around a range of widths and heights, you can also design for screen orientations (e.g. portrait and landscape) and pixel ratios (how the width of each pixel in an image compares to the width theyâre displayed at).
This provides the ability to target devices with obsessive precision. Create an iPad-specific. Target devices with retina displays. While the effort that goes into adding targeted styles may often outweigh the benefits, sometimes it takes only a couple of lines of code to get an email newsletter looking edge-to-edge perfect on both your phone and favorite tablet.
Our friend Andy Clarke created a wonderful boilerplate for targeting popular devices. Itâs a great starting point for designing and building email designs that arenât limited to two views each side of 480px.
Being paranoid about Android
Despite the words stated in the previous section, there are those who are critical of focusing on creating layouts around fixed widths like 480px, commonly known in the industry as âbreakpointsâ. As Marc Drummond argues: âIf you are using responsive web design techniques (and you probably should be!), then this means that using default media query device-width breakpoints is mostly pointless.â â Marc Drummond, âResponsive web design default breakpoints are deadâ
Marc acknowledges that there are plenty of breakpoints that exist outside of something like Andy Clarkeâs earlier boilerplate â particularly amongst Android devices. Besides, new mobile devices come out all the time, so the media query youâre using to target the top-of-the-line Android handset today may be redundant tomorrow.
Building fluid layouts with media queries
The proposed alternative is to design fluid layouts that gracefully adjust to the width of the viewport.
By using a simple media query that applies a percentage width to elementsâinstead of fixed widths, like 320pxâitâs possible for your newsletters to feature content that has a standard desktop view, but stretches and contracts to fit below a certain viewport width. As a result, the newsletter can display optimally in a variety of settings, from larger preview planes to smaller phones like iPhone 7.
Finally, a word of advice: While itâs very easy to become fanatical about tailoring your responsive email design for specific devices, donât lose track of the big picture.
If 85% of your mobile-toting subscribers are viewing your email in 320px x 480px viewports, donât feel like you have to create a @media query for every device. Creating a fluid design that can scale using a combination of percentages and defined pixel widths you will be able to cover a large percentage of your subscribers.
đŸ Optimizing images for mobile
While phone screen sizes have been steadily increasing over the years along with screen resolution, it can be tempting to include more and more images in your emails. But a word of caution: While images can bring an extra wow factor to your emails, images should always be thoughtfully added with accessibility and mobile load times top of mind.
In this chapter, weâll look at some techniques that take advantage of supported CSS properties like background-image. These techniques will not only allow you to display mobile-optimized images throughout your designs, but ensure they look crisp at any width.
Using background images for better headers
Support and the use of background images have been on the rise in the last couple of years thanks in part to increased CSS support utilizing all the benefits that media queries can bring.
One benefit of the increased support is the ability to put live text on images. Another benefit is being able to substitute images when an email campaign is viewed on a mobile device by hiding the original and letting the beautiful, mobile-friendly image shine through.
Background images and live text
In the past, if you wanted to include text on an image, it was created as a single graphic. And if that image didnât load, you were at the mercy of your alt text. Now, with greater support for background images, you can have live text and buttons along with the beautiful images.
Letâs see how this is done.
Background images in Outlook: setting up a DOCTYPE At the top of your HTML email youâll need to declare the DOCTYPE. Doing so informs the browser that this will be an HTML document.
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "https://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
Next, weâll set up our HTML tag, declaring the language as en, which will tell screen readers that this email is written in English. If youâre writing emails in other languages, W3Schools.com has created a list of ISO language codes.
The second half of this code will be a VML or Vector Markup Language declaration, so Microsoft Outlook will allow us to create background images.
<html xmlns="https://www.w3.org/1999/xhtml" lang="en" xml:lang="en"
xmlns:v="urn:schemas-microsoft-com:vml"
xmlns:o="urn:schemas-microsoft-com:office:office">
Next, weâll insert our 120 DPI scaling to target Outlook 2007-2013 and ensure our email scales correctly. This code is placed in the âheadâ tag and outside of the âstyleâ tag.
<!--[if gte mso 9]><xml>
<o:OfficeDocumentSettings>
<o:AllowPNG/>
<o:PixelsPerInch>96</o:PixelsPerInch>
</o:OfficeDocumentSettings>
</xml><![endif]-->
The top of your email should look something like this:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "https://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="https://www.w3.org/1999/xhtml" lang="en" xml:lang="en"
xmlns:v="urn:schemas-microsoft-com:vml"
xmlns:o="urn:schemas-microsoft-com:office:office">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<!--[if !mso]><!-->
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<!--<![endif]-->
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Email Sample</title>
<style type="text/css">
html { width: 100%; }
@media only screen and (max-width: 600px) {
/* Table styles go here */
}
@media only screen and (max-width: 479px) {
/* mobile styles go here */
}
</style>
<!--[if gte mso 9]><xml>
<o:OfficeDocumentSettings>
<o:AllowPNG/>
<o:PixelsPerInch>96</o:PixelsPerInch>
</o:OfficeDocumentSettings>
</xml><![endif]â>
</head>
Next weâll set up the tables and background image.
Within the âtdâ is where weâll add a style and input our background image, declaring the background-position, background-size, and width.
This code will give your email a solid base that will render correctly in Gmail and Apple Mail, including iPhone. But weâre not done yet, we need to make this background bulletproof for Outlook.
Background images in Outlook: bulletproof backgrounds
Stig Morten Myre developed a popular technique to create these bulletproof backgrounds, and even created a handy background image builder. The additional VML, Microsoftâs Vector Markup Language, will allow our background image to render correctly in Outlook, specifically 2007-2019.
If your image is a simple repeated pattern or isnât required to line up in a particular way, then use the same url link for both your âtdâ and VML.
However, if you donât have a repeated pattern background, itâs recommended to have two versions of your image. The first image thatâs linked in your âtdâ should be double the size (i.e. If your email body is 600px wide, your image should be 1200px to render correctly on Retina displays like the new iPhone). The second image thatâs included in your VML should be the exact size (i.e. email is 600px wide, then image is 600px wide).
Hereâs how this could look: In this first example, the same url is used for both, with image size at 1200px wide.
In this comparison, a different url is used in the âtdâ. The image size is 1200px, the VML image url is 600px.
While both examples allow for enough room around the live text, the second example is more visually striking and will more accurately mimic the intended layout and design.
Letâs break down whatâs happening here. First, weâll create a conditional statement [if gte mso 9]. This code creates an if then statement, showing that if Microsoft Office then replace with the following code.
Next weâll declare that this is VML, and set the style with width and height that is appropriate for your selected image. Weâll use the v:fill tag to identify what image URL will be used.
Finally, weâll use the v:shape tag to identify the position, and, as a best practice, restate the width and height and then place our end cap to identify what code will be replaced.
Hereâs what it should look like:
<!--[if gte mso 9]>
<v:rect xmlns:v="urn:schemas-microsoft-com:vml" fill="true" stroke="false" style="width: 600px; height: 320px;">
<v:fill type="tile" src="https://engage.sailthru.com/rs/500-BIA-880/images/Hiking600sm.jpg" color="#ffffff" />
</v:rect>
<v:shape style="position:absolute;width:600px; height: 320px;">
<![endif]-->
<div>
<!-- code we are replacing -->
</div>
<!--[if gte mso 9]>
</v:shape>
<![endif]-->
So letâs put it all together.
<table class="tablescale" width="600" align="center" bgcolor="#ffffff" cellpadding="0" cellspacing="0" border="0">
<tr>
<td width="600" style="border-collapse:collapse; mso-table-lspace:0pt; mso-table-rspace:0pt; background-image: url('https://engage.sailthru.com/rs/500-BIA-880/images/Hiking-Image.jpg'); background-repeat: no-repeat; background-position: top center; background-size: cover; width: 600px;">
<!--[if gte mso 9]>
<v:rect xmlns:v="urn:schemas-microsoft-com:vml" fill="true" stroke="false" style="width: 600px; height: 320px;">
<v:fill type="tile" src="https://engage.sailthru.com/rs/500-BIA-880/images/Hiking600sm.jpg" color="#ffffff" />
</v:rect>
<v:shape id="NameHere" style="position:absolute;width:600px; height: 320px;">
<![endif]-->
<div>
<table class="full" align="center" width="600" cellpadding="0" cellspacing="0" border="0" style="width: 600px;">
<tr>
<td class="left_header" align="center" width="600" style="font-family: Helvetica, Arial, 'sans-serif'; font-size: 35px; line-height: 40px; color:#191919; padding-left: 35px; padding-right: 35px; padding-top: 30px; padding-bottom: 200px; font-weight: 500; width: 600px; ">
<strong>Are you ready for your next adventure?</strong>
</td>
</tr>
</table>
</div>
<!--[if gte mso 9]>
</v:shape>
<![endif]-->
</td>
</tr>
</table>
Itâs generally recommended that images be resized to fit within a viewport of mobile devices. But there are special occasions when your design doesnât allow this, resulting in a small image with illegible text.
Using unique images for mobile devices
If using a background image with live text (as seen in the example above) is not an option, you can create a unique image specifically for mobile devices. This can be accomplished by surrounding the image in a table cell or âdivâ, then creating a media query that hides the original and shows another header image as a background image instead:
@media only screen and (max-device-width: 479px) {
.headerimg {
background-image: url(https://yourdomain.com/images/header-325.png);
width: 100% !important;
height: 115px !important;
}
.imgheader {
display: none;
}
}
<table width="100%" border="0" cellspacing="0" cellpadding="0">
<tr>
<td class="headercell">
<img class=âimgheaderâ src="https://yourdomain.com/images/header.png" border="0" width="600" />
</td>
</tr>
</table>
Hereâs how things look before and after the header images have been swapped out:
An advantage to using this technique is that you can shorten the length of emails by providing significantly shorter images. Or you can restyle your images and text to enhance the mobile experience. When it comes to mobile email, the shorter, the better.
Resizing images for fluid layouts
The issue with the background image swap method above is that itâs really only effective with static-width email designs.
These days, mobile devices can come in all sorts of shapes and sizes, therefore making fluid email layouts a popular option.
While the obvious solution seems to be to set background-size: 100% in the earlier media query, as Elliot Jay Stocks points out, the better option is to use background-size: cover:
@media only screen and (max-width: 600px) {
.imgheader {
width: 100% !important;
}
}
@media only screen and (max-width: 479px) {
.headerimg {
background-image: url(https://engage.sailthru.com/rs/500-BIA-880/images/hero_img_mobile.jpg);
width: 100% !important;
height: 300px !important;
background-position: center !important;
background-repeat: no-repeat !important;
}
.imgheader {
display: none;
}
}
Serving high-res images for Retina displays
Our final tip is in regards to getting images to display as sharply as possible on Appleâs Retina displays. This is one that weâve covered before, but given that these displays arenât going away anytime soon, itâs worth a recap.
The trick is to create key images at twice the size you actually plan on displaying them, thus making the image look super crisp on iPhone 11 and iPad displays. For example, using our earlier background image hack, weâd create a header image that was really 600px x 300px (e.g. https://image.url600@2x.jpg), but then shrink it down for mobile screens.
Hereâs how the media query would look:
@media only screen and (max-width: 600px) {
.imgheader {
width: 100% !important;
}
}
@media only screen and (max-width: 479px) {
.headerimg {
background-image: url(https://image.url200@2x.jpg);
width: 100% !important;
height: 150px !important;
background-position: center !important;
background-repeat: no-repeat !important;
}
.imgheader {
display: none;
}
}
If you specifically want to target Retina displays with a special stylesheet, you can use this CSS declaration instead:
@media all and (min-device-pixel-ratio : 1.5) { ... }
While doubling the size of your images will produce sharp images for larger displays (i.e. iPads and tablets), they can also weigh your emails down, creating slow load times and an overall poor experience for your subscribers.
You can help prevent slow load times with the Save for web options when you export your images from Photoshop or Sketch. You can also utilize an image compressor like TinyPng. For more information on using retina images, we recommend reading this post by Litmus.
đ Optimizing your subscribe forms
Optimizing your email campaigns for mobile isnât just limited to making sure your newsletter can be read on small screens. After all, whatâs the point of sending mobile-optimized campaigns if mobile users canât subscribe to your lists in the first place?
The good news is that mobile devices like iPhone and Android generally do a good job of making forms at least remotely usable these days. However, there are a couple of things designers and coders can do to make them as easy to use as possible. The obvious benefit to optimizing your forms is that they require less time and effort to fill in on a mobile device. To you, this means higher completion rates and more subscribers.
Weâll cover a couple of pointers, and feature a simple example you can use as a starting point for your own subscribe forms.
-
Top-aligned labelsâA common issue when using forms on a mobile device is having labels that reside out of sight when a form field is selected in a browser. At the initial zoom level, a left-aligned label like Enter your email address may be visible, but as soon as you start entering text, the viewport zooms in and the label is flung out of sight. The solution is to either use a top-aligned label, or add the form label as a text-field value. The latter requires less vertical real estate, but can be a little annoying if the field youâve just started filling in was initially hidden by the phoneâs Form Assistant or keyboard.
-
Use input type=âemailââIf you use input type=âemailâ on the email address form field, a special keyboard will display in iOS devices, featuring commonly used characters like @.
-
Narrow down your formsâUse fluid layouts for mobile devices, as you canât predict the viewportâs dimensions or orientation is a best practice. Simply making a text fieldâs width 80% of the viewport width can massively improve the appearance and usability of your subscribe forms.
-
Be mindful of multi-option fieldsâWhile on the subject of narrow layouts, itâs prudent to force all content to flow in a single columnâparticularly checkboxes. Often drop-down lists are a better option over radio buttons and reduce the amount of scrolling required to navigate the form. After youâve created a form, be sure to test it, then have your co-workers test it on their phones to ensure your form is thumb-friendly.
-
Take a stand on scaleâFinally, a lot of these tips here havenât been specific to forms, but more like web design in general. Included is the idea of setting the initial scale or zoom on a mobile device using a viewport meta tag, especially when building standalone forms. When applied, they can prevent the user accidentally zooming in unnecessarily and losing sight of most of the form. Hereâs what a typical viewport meta tag looks like in the head of an HTML page: <meta name = âviewportâ content = âwidth = device-width, user-scalable = noâ />. For a couple of variants on this, check out Appleâs viewport meta tag documentation.
Creating mobile-friendly plain-text email
Not wanting to limit our advice to HTML email design, we wanted to add some pointers for optimizing plain-text campaigns.
When it comes to formatting plain-text emails, there are two camps: those who add a line break every 60-65 characters to their message, and those who donât. Both have pros and cons, depending on which email client your message is viewed in.
60-65 character limit works best in desktop and webmail clients. This is because thereâs effectively no limit to how wide paragraphs of text can run in most reading windows or preview panes. Paragraphs of text can become very much unreadable after 60 characters or so. Traversing from the end of one long line to the beginning of another is just too much visual work for effective scanning.
However, on mobile devices, things are very different. In Apple Mail on iPhone, a 65-character line break combined with wrapping text results in a very jagged message. Itâs arguably worse than reading an infinitely long line of text.
If youâre sending HTML email with a plain-text version containing line breaks, most mobile email clients wonât ever have to fall back to viewing it. So it isnât quite time to undo the appâs handiwork when it automatically creates a nicely formatted text-version of your HTML campaign. However, if youâre sending plain-text campaigns only, itâs worth having a look at your email client usage reports when deciding which way to go. If you have plenty of subscribers reading their email on a mobile device, it may not be an appealing idea to add your own line breaks.
đĄ Case study: Twitter
Letâs put some of these techniques into practice by applying them to a real-world email. Not just any email, but one thatâs sent to millions of people every day.
In the not-so-distant past, Twitterâs email notifications were subpar on mobile devices. The problem was this: a combination of tiny text and wide layouts pushing out the zoom made them nearly unreadable on small screens.
In just five minutes, we applied a simple fix that made a world of difference to the usability and readability of their notifications. And it may potentially help you significantly improve how your email campaigns display on mobile devices, too.
In this case study, weâll show you how we took a humble email notification and turned it into something tweet-worthy when viewed in iPhone or Android Mail, or any mobile email client that supports media queries.
Taming the tiny text First of all, we wanted to approach the most apparent issue with Twitterâs notifications: tiny text. The reason why the text looks so small is because the 710px-wide layout forces the email client on mobile devices to zoom out significantly to view the entire width of the message. Letâs address this with a media query targeting small displays:
@media only screen and (max-width: 479px) { ... }
If youâve read much on responsive email design, you may know that you add these declarations to your âstyleâ tags. The stylesheets within can only be interpreted by HTML email clients that meet the @media-only screen and (max-width: 479px) criteria. So letâs put it to use on adapting the layout here.
First up, there are two tables surrounding the body of the email message:
<table cellspacing="0" cellpadding="0" border="0" width="100%">
<tr>
<td style="background-color:#e9eff2; padding: 30px 15px 0;">
<table cellspacing="0" cellpadding="0" border="0" align="center" width="710" style="font-family: 'Helvetica Neue', Helvetica, Arial, sans-serif; font-size: 16px; color: #333;">
Weâre going to bring them down to size by adding classes wrappertable, wrappercell and structure:
<table cellspacing="0" cellpadding="0" border="0" width="100%" class="wrappertable">
<tbody>
<tr>
<td style="background-color:#e9eff2; padding:30px 15px 0" class="wrappercell">
<table cellspacing="0" cellpadding="0" border="0" align="center" width="710" style="font-family:'Helvetica Neue', Helvetica, Arial, sans-serif;font-size:16px;color:#333" class="structure">
Now that we have something to target, letâs get to work with these classes in our media query:
@media only screen and (max-device-width: 479px) {
body { width: 320px !important; }
.wrappertable { width: 320px !important; }
.structure { width: 300px !important; }
}
The widths used above are significant, as on the iPhone in particular, the display width is 320px in portrait orientation. By narrowing the email layout to 320px, it will be viewed at 100% zoom by default, which means that not only will the whole design be visible, but text and images will look crisp, too.
Putting a harness on the header image
The above technique would be all well and good if it wasnât for that infernally wide âTwitterâ header image. So weâll do something crafty and split the header image into three images. Sections which donât need to be displayed in our new, narrow layout can simply be hidden. Hereâs the original code:
<img alt="Twitter" height="52" src="https://a0.twimg.com/a/1335832060/images/email/email_header_710.png" style="border: 0; display: block;" width="710" />
And here it is, with the header image in three pieces:
<img alt="Twitter" height="52" src="https://yourdomain.com/logo-left.png" style="border:0;" width="41" class="logo"><img alt="Twitter" height="52" src="https://yourdomain.com/logo.png" style="border:0;" width="320"><img alt="Twitter" height="52" src="https://yourdomain.com/logo-right.png" style="border:0;" width="336" class="logo">
You may have noticed the class logo on https://yourdomain.com/logo-left.png and https://yourdomain.com/logo-right.png. Hiding these bits is pretty straightforwardâsimply add the following to our existing media query:
.logo { display: none !important; }
At last, weâve got a header image and layout thatâs trimmed down to size on mobile screens.
Another way to get the same result without slicing images is to create a table row or âtrâ with a background color and then place your logo in the âtdâ.
Hereâs what that code would look like:
<table align="center" width="600" bgcolor="#3BC5F5" cellpadding="0" cellspacing="0" border="0" style="border-collapse:collapse; mso-table-lspace:0pt; mso-table-rspace:0pt; width: 600px;">
<tr>
<td width="600" align="left" valign="bottom" class="logo" style="margin: 0; padding-bottom: 20px; padding-top: 20px; padding-left: 30px; font-size:18px; color:#ffffff; font-family: Helvetica, Arial, sans-serif; width: 600px; ">
<a href="url_twitter" target="_blank">
<img class="logo" src="twitter_img_logo.png" width="165" alt="Twitter" border="0" style="display: inline-block; color: #ffffff; width: 165px; color: #ffffff; font-size: 20px; line-height: 26px;" />
</a>
</td>
</tr>
</table>
Now, on top of the above re-factors, we added some extra padding around elements and adjusted font sizes to taste.
Licenses & certifications
- đ LeetCode Global TOP 200 (TypeScript: Certificate, Sources: TypeScript).
- đ Golden Award for the Year of the Tiger Challenge (TypeScript: Certificate, Sources: Codility).
- 2022 July LeetCode Challenge (2022-07-31).
- 2022 June LeetCode Challenge (2022-06-30).
- 2022 May LeetCode Challenge (2022-05-31).
- 2022 Apr LeetCode Challenge (2022-04-30).
- LeetCode Dynamic Programming (2022-05-07).
- Graph Theory (2022-04-30).
- SQL (2022-04-26).
- Algorithm I (2022-04-30), Algorithm II (2022-05-21).
- Data Structure I (2022-04-30), Data Structure II (2022-05-21).
- Binary Search I (2022-04-28), Binary Search II (2022-05-18).
- Programming Skills I (2022-04-28), Programming Skills II (2022-05-18).
- LinkedIn Skill Asessment (Front-End): Front-end Development, Angular, React, Javascript, HTML, CSS, jQuery.
- LinkedIn Skill Asessment (Back-End): Node.js, Java, Spring Framework, Scala, C#, .NET Framework, Unity, Python (Programming Language), Django, PHP, C (Programming Language).
- LinkedIn Skill Asessment (Databases): MongoDB, NoSQL, Transact-SQL (T-SQL), MySQL.
- LinkedIn Skill Asessment (Infra/DevOps): Bash, Git, Amazon Web Services (AWS), AWS Lambda, Google Cloud Platform (GCP), Microsoft Azure, Hadoop, IT Operations.
Contacts
I have a clear focus on time-to-market and don't prioritize technical debt. And I took part in the Pre-Sale/RFX activity as a System Architect, assessment efforts for Mobile (iOS-Swift, Android-Kotlin), Frontend (React-TypeScript) and Backend (NodeJS-.NET-PHP-Kafka-SQL-NoSQL). And I also formed the work of Pre-Sale as a CTO from Opportunity to Proposal via knowledge transfer to Successful Delivery.
đ©ïž #startups #management #cto #swift #typescript #database
đ§ Email: sergey.leschev@gmail.com
đ LinkedIn: https://linkedin.com/in/sergeyleschev
đ Twitter: https://twitter.com/sergeyleschev
đ Github: https://github.com/sergeyleschev
đ Website: https://sergeyleschev.github.io
đ DEV Community: https://dev.to/sergeyleschev
đ Reddit: https://reddit.com/user/sergeyleschev
đ Quora: https://quora.com/sergey-leschev
đ Medium: https://medium.com/@sergeyleschev
đšïž PDF: Download
ALT: SIARHEI LIASHCHOU