JK
20
What is your favorite hack?
Building/designing emails has long been a hacker's battle. What are some tricks you've used or seen that you think are really clever?
Building/designing emails has long been a hacker's battle. What are some tricks you've used or seen that you think are really clever?
<!--[if gte mso 9]>
Please get a better email client
<![endif]-->
Lol. Definitely a fun one. Also, thanks for pointing out that this forum doesn't properly sanitize HTML :P
For those wondering, the hack is:
hahaha. nice.
@Mark/Jonathan - sorry about the formatting, we had a bit of an issue where html comments weren't being escaped, but that should be fixed now!
Hands down the greatest email hack ever is:
Essentially, it splits -webkit-supported email clients and non-webkit-supported email clients. This way, you can build a solid foundation & then optimize for more modern/advanced clients for better experiences. I elaborated more on this hack here.
I have a blog post coming out soon-ish that goes into more detail behind the methods I've used this media query =).
I know Outlook.com supports media queries on desktop (but not on the mobile version of webmail) so media query targeting of cool webkit stuff could lead to some errors in that.
Kevin, you might want to read this:
http://blogs.msdn.com/b/ie/archive/2014/07/31/the-mobile-web-should-just-work-for-everyone.aspx
In the latest version of Windows Phone 8.1 (GDR1). IE 11 has been changed significantly. The IE dev team have decided to implement some webkit properties in conjunction with modifying the UA string of IE 11 itself for better compatibility of the web. This means that your webkit media query will actually report as TRUE, so as a feature detection method, this has slightly hampered its purpose!
I get the basic point of this. But is this mostly to avoid targeting Windows Phone? Just wondering the benefits of:
over simply
Given that the latter, paired with attribute selectors, would target essentially the same clients and accomplish the same thing. Unless i'm not thinking of a certain non-webkit client that also supports media queries. Which might also be the case. :)
@Mark
But if the email client itself allows it, would the preferred approach not be similar to how you would approach this on the web? For instance, there isn't much available in webkit that you can't also do in mozilla. So, if it's not something that Outlook.com itself is hindering, why would you only deliver that to Chrome/Safari and not to Firefox?
That approach doesn't seem to make much sense to me.
@Brian
Good point, may need to do some testing on this a little further.
certainly at the top of the list- ;-)
Just discovered this one for use when designing and debugging:
It allows you to easily see the different depths of nodes along with each elements padding, margins, etc. Can be handy for easily identifying any inconsistencies.
Example:

Creating a ghost column in between aligned tables to make it work in Outlook:
Saved me hours of headaches.
From: http://labs.actionrocket.co/make_mobile_email_work_in_outlook
This hack needs more recognition, because its probably the most elegant conditional hack for Outlook yet. This one line conditional comment solves so much pain.
Props to Mike Ragan from Action Rocket.
This is indeed the best hack. Helped me a lot.
My favourite right now is using Margin (with a capital M) to fool Outlook.com! It strips out margin but not Margin. And of course, they could wise up someday and start stripping Margin as well, but it's not like we had any warning the first time and we might as well make the most of it while it works :)
(Full credit to a chap called Wiktor who suggested this in a comment buried way down on this post https://www.campaignmonitor.com/blog/post/3921/outlook.com-drops-margin-and-float-support-entirely)
Amazing.
Love this trick.
Nice one! Doesn't work in Lotus 8/8.5 right?
It works in Lotus 8/8.5 - just tested it.
Doesn't work in Lotus 6.5/7.
Nicole Merlin: thanks for the good tip!
No worries! Yeah, it's true that it does not work in earlier versions of Lotus Notes, but I almost never support those versions.
Adding linebreaks on mobile with pseudo classes and media queries.
in the responsive media query. The actual email has:
In Desktop, it will show as:
while on Mobile it will show as:
As well as the outlook conditional comment (which has got me out of many a scrape) I also love...
Webkit targeting for CSS animation, HTML video and SVG images
This (better than mine) solution for hiding content on non-mobile
http://freshinbox.com/blog/bulletproof-solution-to-hiding-mobile-content-when-opened-in-non-mobile-email-clients/
Bullet proof buttons and backgrounds http://buttons.cm/ http://backgrounds.cm/
I recently found a way to do CSS triangles in email http://emailcodegeek.com/css-triangles/
CSS Triangles are very cool! Nice work
The CSS triangles code above doesnt work for gmail
min-width:600px
; in a full width img to force gmail's android app to not do it's weird text zoom. If responsive, just put it in a full width spacer that is hidden at the first break point.I use the CSS selectors :before and :after to optimize button text for a given environment. For example, in a footer I might have a forward-to-friend link with the text "Share" on the desktop version, but in the mobile version the link becomes its own full-width footer button. Now that I have more space for some text, I might use:
The result is a full width button reading, "Share this Email".
Sneaking in preview text that many clients like Gmail display after the subject line. How often does the email preview start with "having trouble viewing...." I use a div tag
The text above is not displayed in the message but it's like a second subject line
Wouldn't this get flagged as spam in some clients? or at least increase the probability of that happening?
I've wondered the same thing in the past. I know this is how ExactTarget drops the text in emails that are using their preheader tool though. So, I would assume they tested this prior to implementing the tool.
I think it would, yes.
I usually put pre-header text in the alt tag of my "plan B" 1x1 gif I have right after the opening body tag.
I've used this a few times to change "Click" to "Tap"
And here's the HTML.
Doesn't work with gMail, right?
You can simulate classes and use pseudo-classes in Gmail by doing using attribute selectors on attributes that Gmail does not strip:
Then in the code
http://freshinbox.com/blog/interactive-emails-in-gmail-using-css-attribute-selectors/
Love using for this for hover states with images or background colors
I wrap the images in divs to fix gaps in OWA (Outlook Web App):
Throwing this little snippet at the bottom of your email stops Gmail mobile from resizing everything and making it look terrible:
To prevend that empty td's with a height of 1px becomes 10px in Outlook 2013.
and
For support of media queries in the mail app of WP8
The support of media queries for WP8 as mentioned, doesn't work for outlook-exchange accounts - so if you ever wondered... :-)
See related article here:
http://blog.jmwhite.co.uk/2014/03/01/windows-phone-does-support-css3-media-queries-in-html-email/
Thanks for referencing my article!
A more detailed explanation of why this is the case can be found here:
http://blog.jmwhite.co.uk/2014/08/19/email-campaigns-windows-phone-part-3-exchange-activesync/
The summary is basically the EAS (Exchange ActiveSync) protocol has its own HTML/CSS rendering capabilities, but in similar Microsoft fashion, these capabilities are rather limited, i.e. no CSS3, even CSS2 support is questionable. This isn't just for Windows Phone, the same happens on iOS and Android.
Tried to apply your fix for the empty tds in Outlook 2013 and couldn't seem to get it to work. Well the tests were a bit inconclusive. It just looks like sometimes Outlook 2013 decides to obey the CSS and the height, but other times, it'll just wack the cell up to 10px.
Could you try the following:
I ended up trying
(Mark Robbins pointed me that way) Which worked a treat, but the only if the td wasn't empty, and had a
instead. BUT ... strangely, this didn't work for Outlook 2013 when I tried to apply it to tds that were nested in a further table.
Gave up an just applied 1px borders to tables and tds instead.
I use it like this:
The only thing you have to add is a line-height on td's with text. Could you try it like this?
Just check this:
Just work for me, even if cell is empty (even without nbsp it works).
I was fighting with tihs one:
But for Outlook it is a black magic and didin't work, and I didn't find a solution for that. Most of email clients work fine, even Outlook 2010 but not Outlook 2013.
Make your preheader only appear in the preview:
<span class="preheader" style="display:none !important;">Preheader text goes here</span>
(via http://team-email.co.uk/hidden-preheaders-save-screen-real-estate/)I have found that span at times doesnt work properly example if the template is going thru an editor, CKEditor for example. Creating a hidden div tag works here.
Span on the other hand is perfect for managed ones :-)
Cheers
Definitely one of my favorites!
An old hack, but a good one. Get rid of the unwanted left margin on Android 4.4 by using this within your <style> tag:
body { margin: 0 auto !important; }
div[style*="margin: 16px 0"] { margin: 0 auto !important; font-size:100% !important; }
Before fix (with unwanted margin-left):
After fix:
I add a div around image tags to fix these annoying gaps in OWA
Do you have any more info on this? I just noticed it the other day and have tried wrapping my
img
with a div but that just gets nested within the div OWA adds?Try this:
<div style="height:163px; font-size:0;"><img src="http://image.jpg" target="_blank" border="0" style="display:block;" height="163" width="600"></div>
Forcing outlook to render my line-height-settings correct with:
style:"mso-line-height-rule: exactly; line-height: 22px;"
just working on block-elements.If you set line-height on a link:
<a href="#" style="display:block; line-height:22px;"
you get a nice full width hit area matching the<td>
line-height would have to be fixed for mobile when wrapping occurs
Sometimes I use this one:
<!--[if !gte mso 9]><!--> ... <!--<![endif]--><!--[if gte mso 9]> ... <![endif]-->
2nd fav is:
mso-hide:all;
Beware that mso-hide tends to break when a message is forwarded!
One important thing about
mso-hide:all
is that if you have nested tables, this style must be applied to table in the block you want to hide or else content within it will not be hidden.Definitely the hack that allows you to hide entire parts of an e-mail cross desktop and mobile. This allows you to restructure the e-mail entirely for mobile users and display basically another set of HTML for the parts you wish to place.
Various solutions were offered. Here is a reference to one of them:
"Bulletproof Solution to Hiding Mobile Content when opened in Non-Mobile Email Clients", FreshInbox (2014)
http://freshinbox.com/blog/bulletproof-solution-to-hiding-mobile-content-when-opened-in-non-mobile-email-clients/
I have a trick to create padding. You have to nest pretty deeply to pull it off, but it renders quite consistently. I use rows to add space above and below, and use cells to pad left and right, and fill in the rows and cells with non-breaking spaces.
This is part of a gmail div inline-block hack.
The same could be achieved with a lot less code, unless all the extra code is necessary for the hack: