{"id":214,"date":"2014-01-15T07:45:16","date_gmt":"2014-01-15T07:45:16","guid":{"rendered":"http:\/\/freshinbox.com\/blog\/?p=214"},"modified":"2017-08-25T22:07:03","modified_gmt":"2017-08-25T22:07:03","slug":"bulletproof-solution-to-hiding-mobile-content-when-opened-in-non-mobile-email-clients","status":"publish","type":"post","link":"https:\/\/freshinbox.com\/blog\/bulletproof-solution-to-hiding-mobile-content-when-opened-in-non-mobile-email-clients\/","title":{"rendered":"Bulletproof Solution to Hiding Mobile Content when opened in Non-Mobile Email Clients"},"content":{"rendered":"<p>This is a definitive guide into hiding content on desktop and web clients that you only want displayed on mobile email clients.<\/p>\n<p>These days, responsive design is getting popular on email. Having the layout and sizes of elements change when viewed on a desktop vs mobile environment make for a much more pleasing email experience for the recipient.<\/p>\n<p>The question is,\u00a0what is the best way to hide content that you only want seen on a mobile device &#8211; such as a call to action to try out your mobile app or a clever layout trick &#8211; so that it is not displayed when the user opens on an email on a desktop or web client?<\/p>\n<div style=\"max-width:400px;margin:20px auto;padding:10px;border:2px solid #AC88AC;text-align:center;border-radius:3px;\">\nEver considered adding interactivity into your email?<br \/>\n<a href=\"https:\/\/freshinbox.com\/resources\/tools\/carousel\/\">Try out the Image Carousel for Email Tool<\/a>.\n<\/div>\n<p>The proper way to hide content is to style a content with &#8220;display:none&#8221;, however due to the quirks on email clients such as Yahoo! Mail and Outlook 2007, 2010 and 2013 (Outlook 2007\/10\/13), its not as straightforward.<\/p>\n<p><span style=\"text-decoration: underline;\">The markup below will do the trick:<\/span><\/p>\n<pre class=\"lang:default decode:true\">&lt;!--[if !mso]&gt;&lt;!--&gt;\r\n&lt;div class=\"mobilecontent\" style=\"display:none;max-height:0px;overflow:hidden;\"&gt;\r\n  MOBILE CONTENT\r\n&lt;\/div&gt;\r\n&lt;!--&lt;![endif]--&gt;<\/pre>\n<p>An alternate way to hide content within Outlook is using the mso-hide:all technique. However this technique requires that you apply this style to any nested tables as well:<\/p>\n<pre class=\"lang:default decode:true \" >&lt;div class=\"mobilecontent\" style=\"mso-hide:all;display:none;max-height:0px;overflow:hidden;\"&gt;\r\n  MOBILE CONTENT\r\n&lt;\/div&gt;\r\n<\/pre>\n<p><B>Warning:<\/B> Make sure to put this on a div and not on a table. You can nest the table within the div if needed. This is because Yahoo! Mail will strip display:none and max-height cannot be applied to tables.<\/p>\n<p><span style=\"text-decoration: underline;\">To show the content within mobile clients you add a media query:<\/span><\/p>\n<pre class=\"lang:default decode:true\">&lt;style&gt;\r\n\u00a0@media screen and (max-device-width: 480px) {\r\n  div[class=mobilecontent]{\r\n    display: block !important;\r\n    max-height: none !important;\r\n  }\r\n}\r\n&lt;\/style&gt;<\/pre>\n<p><b>The Breakdown<\/b><\/p>\n<p>The following example actually uses three forms of content hiding, yes THREE.<\/p>\n<p><strong>1) display:none<\/strong><\/p>\n<p>This is the &#8220;proper&#8221; way to hide elements in HTML. However Yahoo! Mail (Gmail also previously (before 2016)) strips out styles marked display:none effectively displaying the content and Outlook 2007\/10\/13 is a bit temperamental when it comes to that rule (explained below). So although for the majority of the clients display:none will work we still need to do more. Modern mobile email clients however seem to abide by that rule so hiding content within mobile is more straightforward.<\/p>\n<p><strong>2) Gmail and max-height<\/strong><\/p>\n<p>Yahoo! Mail (Gmail also previously) strips out display:none so the next best option is to set an element&#8217;s height to 0 pixels. However strangely enough, Yahoo! Mail converts CSS height rules to min-height \u2013 which defeats our intended purpose. However there\u2019s another CSS rule that we CAN use, and that is max-height. So together with setting the overflow to hidden, &#8220;max-height: 0px; overflow: hidden;&#8221; will hide content within Gmail.<\/p>\n<p>Unlike display:none however, setting the max-height of an element to 0 will not hide any borders set on the element itself. So if you want to hide an element with borders, you need to wrap that element with a div and set that div\u2019s max-height and overflow instead.<\/p>\n<p><strong>3) Outlook 2007\/10\/13 and conditional comments (See update)<\/strong><\/p>\n<p>The CSS rule display:none works with Outlook 2007\/10\/13\u00a0unless there is a table within the element you want to hide. In that case the table\u2019s contents will be visible even though everything else is hidden.<\/p>\n<p>As every seasoned email designer knows, Microsoft Outlook took a turn for the weird with the introduction of Outlook 2007. Its workings have been a <a href=\"http:\/\/www.emailonacid.com\/blog\/details\/C6\/tips_and_tricks_outlook_07-13\" target=\"_blank\">mystery since<\/a>. Microsoft knows about it and for some strange reason decided not to do anything about it \u2013 the first person who is able to get an adequate explanation from Microsoft gets a shout out on this blog!<\/p>\n<p>Nevertheless, Outlook has provided us with a simple solution: conditional comments. Conditional comments is a Microsoft proprietary markup that instructs their clients on how to render content within the comment blocks.<\/p>\n<p>The markup below will allow you to hide any content within Microsoft Outlook 2007\/10\/13. Other clients will simply ignore the comments.<\/p>\n<pre class=\"lang:default decode:true\">&lt;!--[if !mso 9]&gt;&lt;!--&gt;\r\n  CONTENT HIDDEN FROM OUTLOOK 2007\/10\/13\r\n&lt;!--&lt;![endif]--&gt;<\/pre>\n<p>In this case, the comment is saying if the version of MS Office is not 9, show the content, otherwise, hide it. A good resource is Campaign Monitor&#8217;s post <a title=\"Using Conditional Comments to Target Outlook 2007\" href=\"http:\/\/www.campaignmonitor.com\/blog\/post\/1774\/using-conditional-comments-to-1\/\" target=\"_blank\">Using Conditional Comments to Target Outlook 2007<\/a>.<\/p>\n<p><b>Displaying the Hidden Content on Mobile Clients<\/b><\/p>\n<p>The vast majority of users on mobile (iPhone\/Android) use the platform\u2019s native email client and those clients support the media query example above and displays the content since the device width is below 480pixels (Should mobile clients start getting wider, that number may need to change).<\/p>\n<p><b>Content may remain hidden on some mobile clients.<\/b><\/p>\n<p>However, a small percentage of users use either the apps or mobile website version of Gmail, Outlook.com (Hotmail), and Yahoo! Mail. Unfortunately when viewing on these email clients, the content will remain hidden. This is because these clients either don\u2019t support media queries or they strip embedded styles \u2013 both are a requirement to selectively display or hide content within an email based on the email client. See <a href=\"https:\/\/freshinbox.com\/blog\/email-client-media-query-and-embedded-styles-support-2014\/\">Email Client Media Query and Embedded Styles Support<\/a> for the list of mobile email clients that support media queries.<\/p>\n<p><b>Takeaway<\/b><\/p>\n<ul>\n<li>Hiding content on web and desktop clients are harder than on mobile clients.<\/li>\n<li>To hide an element with borders, wrap it with a div and apply the technique to the wrapping div to ensure the element including its borders are hidden in Gmail.<\/li>\n<li>Hidden content may remain hidden on certain mobile clients which don\u2019t support media queries<\/li>\n<\/ul>\n<p><em>(<a href=\"http:\/\/www.flickr.com\/photos\/cmcbrien\/6846818932\/\">Photo<\/a> by <a href=\"http:\/\/www.flickr.com\/photos\/cmcbrien\/\">c.mcbrien<\/a>)<\/em><\/p>\n<p><BR><BR><br \/>\n<div style=\"padding:10px; border: 2px solid #99C731;background-color:#FFF8DC;border-radius:5px;\">\n<form action=\"https:\/\/freshinbox1.createsend.com\/t\/i\/s\/adrmi\/\" method=\"post\" id=\"subForm\">\n<span class=\"fisub_header\" style=\"font-weight:bold;\">Subscribe to the #EmailGeeks Newsletter<\/span>\n<p><input id=\"fieldEmail\" name=\"cm-adrmi-adrmi\" type=\"email\" style=\"width:90%\" required placeholder=\"Your Email Address\" \/><\/p>\n<p><button type=\"submit\">Subscribe<\/button><\/p>\n<\/form>\n<\/div><\/p>\n","protected":false},"excerpt":{"rendered":"<p>This is a definitive guide into hiding content on desktop and web clients that you only want displayed on mobile email clients.<BR><BR><\/p>\n<p>These days, responsive design is getting popular on email. Having the layout and sizes of elements change when viewed on a desktop vs mobile environment make for a much more pleasing email experience for the recipient.<BR><BR><\/p>\n<p>The question is,\u00a0what is the best way to hide content that you only want seen on a mobile device &#8211; such as a call to action to try out your mobile app or a clever layout trick &#8211; so that it is not displayed when the user opens on an email on a desktop or web client? &#8230;<\/p>\n","protected":false},"author":2,"featured_media":229,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":[],"categories":[23,28],"tags":[32,8,11,10,5,16,9,4,14,18,29,31,15,13],"_links":{"self":[{"href":"https:\/\/freshinbox.com\/blog\/wp-json\/wp\/v2\/posts\/214"}],"collection":[{"href":"https:\/\/freshinbox.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/freshinbox.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/freshinbox.com\/blog\/wp-json\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"https:\/\/freshinbox.com\/blog\/wp-json\/wp\/v2\/comments?post=214"}],"version-history":[{"count":27,"href":"https:\/\/freshinbox.com\/blog\/wp-json\/wp\/v2\/posts\/214\/revisions"}],"predecessor-version":[{"id":3444,"href":"https:\/\/freshinbox.com\/blog\/wp-json\/wp\/v2\/posts\/214\/revisions\/3444"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/freshinbox.com\/blog\/wp-json\/wp\/v2\/media\/229"}],"wp:attachment":[{"href":"https:\/\/freshinbox.com\/blog\/wp-json\/wp\/v2\/media?parent=214"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/freshinbox.com\/blog\/wp-json\/wp\/v2\/categories?post=214"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/freshinbox.com\/blog\/wp-json\/wp\/v2\/tags?post=214"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}