Bulletproof Solution to Hiding Mobile Content when opened in Non-Mobile Email Clients
This is a definitive guide into hiding content on desktop and web clients that you only want displayed on mobile email clients.
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.
The question is, what is the best way to hide content that you only want seen on a mobile device – such as a call to action to try out your mobile app or a clever layout trick – so that it is not displayed when the user opens on an email on a desktop or web client?
Try out the Image Carousel for Email Tool.
The proper way to hide content is to style a content with “display:none”, 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.
The markup below will do the trick:
<!--[if !mso]><!--> <div class="mobilecontent" style="display:none;max-height:0px;overflow:hidden;"> MOBILE CONTENT </div> <!--<![endif]-->
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:
<div class="mobilecontent" style="mso-hide:all;display:none;max-height:0px;overflow:hidden;"> MOBILE CONTENT </div>
Warning: 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.
To show the content within mobile clients you add a media query:
<style> @media screen and (max-device-width: 480px) { div[class=mobilecontent]{ display: block !important; max-height: none !important; } } </style>
The Breakdown
The following example actually uses three forms of content hiding, yes THREE.
1) display:none
This is the “proper” 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.
2) Gmail and max-height
Yahoo! Mail (Gmail also previously) strips out display:none so the next best option is to set an element’s height to 0 pixels. However strangely enough, Yahoo! Mail converts CSS height rules to min-height – which defeats our intended purpose. However there’s another CSS rule that we CAN use, and that is max-height. So together with setting the overflow to hidden, “max-height: 0px; overflow: hidden;” will hide content within Gmail.
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’s max-height and overflow instead.
3) Outlook 2007/10/13 and conditional comments (See update)
The CSS rule display:none works with Outlook 2007/10/13 unless there is a table within the element you want to hide. In that case the table’s contents will be visible even though everything else is hidden.
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 mystery since. Microsoft knows about it and for some strange reason decided not to do anything about it – the first person who is able to get an adequate explanation from Microsoft gets a shout out on this blog!
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.
The markup below will allow you to hide any content within Microsoft Outlook 2007/10/13. Other clients will simply ignore the comments.
<!--[if !mso 9]><!--> CONTENT HIDDEN FROM OUTLOOK 2007/10/13 <!--<![endif]-->
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’s post Using Conditional Comments to Target Outlook 2007.
Displaying the Hidden Content on Mobile Clients
The vast majority of users on mobile (iPhone/Android) use the platform’s 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).
Content may remain hidden on some mobile clients.
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’t support media queries or they strip embedded styles – both are a requirement to selectively display or hide content within an email based on the email client. See Email Client Media Query and Embedded Styles Support for the list of mobile email clients that support media queries.
Takeaway
- Hiding content on web and desktop clients are harder than on mobile clients.
- 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.
- Hidden content may remain hidden on certain mobile clients which don’t support media queries
The display:none was new to me…
You have to change
max-height: none !important;
to
max-height: 0 !important;
It works for me. Thanks. Good post!
Hi Mario,
Thanks for checking out the site! I’m not quite sure I follow your statement. In the example max-height: 0px is used to hide the content and max-height: none !important was used to unhide it when viewed in mobile.
Hey Justin,
Cheers loads for this. I’ve just tested and outlook.com isn’t playing ball though! Any ideas?
Hi Todd, Can you provide me more context on what is happening on Outlook.com? For Outlook.com simply adding the style display:none should hide whatever block you’re trying to hide.
This will hide in anything outlook, including outlook.com
Works for me.
Hi
thank you for the great tip.
CONTENT HIDDEN FROM OUTLOOK 2007/10/13
<!–
Was very useful especially when display:none does not seem to work.
Simply awesome!
cheers
Ashar
Thank you Ashar. Sometimes you just need to hide things in Outlook if you can’t style them the way you need to.
Just a quick FYI…tried using the “mso-hide:all” to try and hide an image contained within a table and I’m getting some inconsistent results in some versions of Outlook.
Outlook 2000, 2002/XP, 2003 and 2011 hide the table without any problems.
Outlook 2007, 2010 and 2013 show the table
Hi Stephen,
Thanks for the observation (your follow up comment got mangled since the comment system doesn’t like HTML comments in markup).
One side-effect of mso-hide:all is that if there are nested tables, this style also needs to be applied to them as well (I will update the article to reflect this).
— Justin
Very helpful article ! Thanks a lot !
does this work with phone number links you only want displayed on mobile?
Hi Megan,
If you’re referring to links containing the prefix tel://, I’m not sure if this would be an ideal solution as its meant to hide blocks of content and not parts of text.
This exactly the best coding tweaks when you want to target a desktop and mobile site. I have been using this for more than a year and have no issues on mobile/desktop rendering – except the crap lotus notes / and blackberry email app.
Hi,
Do you have a solution that works to hide the mobile version in Lotus Notes? My email is rendering fine in every other inbox but in Lotus Notes both the desktop and mobile versions are displayed- one under the other. Any help would be much appreciated.
Thanks
Hey Ada,
Which version of Lotus Notes are you referring to? This method should work with Lotus Notes 8.5 and above.
Hi,
I have this problem too with Lotus Note 7.
Thanks
I have this problem with IBM Notes 9.
This is very helpful. One thing, yahoo mail app does not like display:none. If you have that in your inline css, it will still display the element. I’m not sure what the app is wiping out in terms of the css in the head tag, but anytime I have a display:none in the inline css, it does not hide the element. Just wanted to share that. Having max-height:0 should help, but if not sometimes setting the width to 0px as well and changing that in the media queries also helps.
Actually I got myself backwards, If you want an element to show in yahoo mail app then you have to leave out the display: none in the inline css. Apparently my brain isn’t working this morning :)
Great Article, Justin. Have you done much testing on Outlook iOS app – I need to hide content where the “kinetic” code (checked) does not work – any ideas?
Gavin, you can use the fallback method covered in the Tabs for Email article. Basically, wrapping the interactive content with a DIV and a checked checkbox and displaying the DIV if the :checked selector is activated.
http://freshinbox.com/blog/interactive-tabs-for-email/
Thank you for the post!
For some reason I cannot get this to show again when on mobile. I’ve tried iPhone 5, 6 & 6+, iOs 7 & 8.
Anyone having problem with text alignment of the hidden text? I have some problems, I am not able to center the text in the div….
mso-hide:all works for hiding content in outlook 2010, 2011 and 2013 for me but not for outlook.com. Any advice on how to hide mobile content for outlook.com email please?
Many thanks.
Hey Olu, display:none works in Outlook.com.
Check out this CSS support grid: http://freshinbox.com/resources/css.php
Thanks Justin. It works as an inline css :)
Justin, this helped me SO much! I’ve been struggling with hiding some mobile elements in Outlook. Thanks a bunch! –Keep up the amazing work you’re doing! You ROCK! :)
Thanks for the fantastic guide. This helped me a lot, I was starting to pull my hair out.