I'm working on an HTML email and I am using MailChimp's Responsive Email Templates in combination with their CSS inliner tool. For the most part, the email looks great across the myriad of email clients, but in Gmail things are horribly misrepresented.
If I use Gmail's "Show original" option from the drop down menu next to the reply arrow, the original HTML is different from what is actually displayed in the email client. I can confirm this by inspecting the element with the developer tools. This happens on desktop and mobile; the email client is removing inline style attributes from elements.
It seems that one of the criteria for removing the style attribute is if the element also contains a class. Can anyone confirm this? Also, it appears to remove all style attributes from a table tag regardless. Can anyone confirm this as well?
What are the workarounds for this?
Screenshots of email with source in Gmail and Yahoo included below.
Screenshot of email in Gmail with source displayed via Chrome developer tools
Screenshot of email in Yahoo with source displayed via Chrome developer tools
Just thought I'd add this in to the mix. I encountered as this problem as well and when looking at the raw source I realized that the 8-bit encoding was splitting lines in odd places due to the 1000 character limit, so I was ending up with content like this:
Solution is to base64 encode the content and use chunk split or whatever tools you have to accomplish the same.
In php I did
$html = chunk_split(base64_encode($html))
and then setContent-Transfer-Encoding: base64
. Now gmail loves me.I just checked now: Gmail strips out your inline style attribute if you don't put spaces between
;
,,
and:
charsthis works fine:
but the same rule will be stripped out if you don't use spaces; if you write this:
you will get this output on Gmail client:
EDIT:
In addition to this behavior, I noticed that Gmail tends to strip out the inline style if you declare a
font-family
inside a nested<table>
or a<td>
, I'm still not sure on what is the general rule of its preprocessor, I checked on Google but I can't find any official documentation about html mail composition for Gmail.As someone who regularly codes emails for marketing campaigns at my job, I feel your pain. Gmail, along with many other email clients, can be a bit funky to code for. For one, it strips out any CSS that's outside the body. So putting in things like media queries and document level styles don't work. The best piece of advice I can give you is hand code your inline CSS and try to avoid anything fancy. In fact, if you can use an HTML attribute to do your styling, use that in place of any CSS. An example would be bgcolor instead of background-color.
Here is an article related to your specific problem I found. Best of luck.
There are multiple work arounds for gmail. Gmail is quite a joker when it comes to your styling, as it'll strip what it doesn't like completely out of your e-mail.
Here are some little tips:
Gmail adds white space between images, or stretched the size of it's container td: You can correct this by specifying style="display:block" on your images (Make sure your TD has the same width and/or height as your image).
Gmail renders black links as blue links: Yes, this is ugly. Use #000001 instead of #000000.
Gmail makes phone numbers clickable: That may be a good thing or not, depending on your client, but one way to work around that is to include an empty anchor tag with styles around the phone number.
Ex:
<a style="color:#000001; text-decoration:none;>555 555-5555</a>
. It will make you feel ashamed of your code, but it's an effective little hack.Using CSS selectors is another workaround that I was able to use. In my example I am trying to format a HTML table. I found gmail stripped out all the ID and CLASS attributes rendering my CSS useless.
After some investigation I noticed gmail did not remove my title attribute. So I created a CSS rule using a title selector. This appeares to work fine:
I don't think this is best practice, but I thought I would mention it.