Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

HTML email in Gmail - CSS style attribute removed

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

enter image description here


Screenshot of email in Yahoo with source displayed via Chrome developer tools

enter image description here

like image 616
Matty B Avatar asked Jul 11 '13 20:07

Matty B


People also ask

Does Gmail strip CSS?

Gmail does not allow negative CSS margin values If you're trying to overlap page elements in your HTML email using negative margin values, you'll find Gmail CSS not working as you intended.

Can I use style tag in HTML email?

Yes you can. However you have to keep in mind that few email clients respect css standards. Just stick to basic css properties like margin and padding , etc., and it should all be fine. Also you can style your html elements inline ( <div style=""> ) though it's not an elegant solution.


1 Answers

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.

like image 191
Matt Whitehead Avatar answered Sep 23 '22 20:09

Matt Whitehead