218

I'm designing an HTML template for an email newsletter. I've learned that many email clients ignore linked stylesheets, and many others (including Gmail) ignore CSS block declarations altogether. Are inline style attributes my only choice? What are the best practices for styling HTML emails?

dippas
  • 58,591
  • 15
  • 114
  • 126
Joe Mornin
  • 8,766
  • 18
  • 57
  • 82
  • 1
    Here is a [big list of resources](http://stackoverflow.com/questions/2229822/html-email-best-practices-considerations-and-how-to-write-code-for-outlook-gma/21437734#21437734) on a [duplicate question](http://stackoverflow.com/questions/2229822/html-email-best-practices-considerations-and-how-to-write-code-for-outlook-gma/). – John May 15 '14 at 21:08

7 Answers7

280

I've fought the HTML email battle before. Here are some of my tips about styling for maximum compatibility between email clients.

  • Inline styles are you best friend. Absolutely don't link style sheets and do not use a <style> tag (GMail, for example, strips that tag and all it's contents).

  • Against your better judgement, use and abuse tables. <div>s just won't cut it (especially in Outlook).

  • Don't use background images, they're spotty and will annoy you.

  • Remember that some email clients will automatically transform typed out hyperlinks into links (if you don't anchor <a> them yourself). This can sometimes achieve negative effects (say if you're putting a style on each of the hyperlinks to appear a different color).

  • Be careful hyperlinking an actual link with something different. For example, don't type out http://www.google.com and then link it to https://gmail.com/. Some clients will flag the message as Spam or Junk.

  • Save your images in as few colors as possible to save on size.

  • If possible, embed your images in your email. The email won't have to reach out to an external web server to download them and they won't appear as attachments to the email.

And lastly, test, test, test! Each email client does things way differently than a browser would do.

Michael Irigoyen
  • 22,513
  • 17
  • 89
  • 131
144

Campaign Monitor have an excellent support matrix detailing what's supported and what isn't among various mail clients.

You can use a service like Litmus to view how an email appears across several clients and whether they get caught by filters, etc.

Jim
  • 72,985
  • 14
  • 101
  • 108
  • 9
    +1:Didn't know about Litmus. This looks like a huge time saver. Thank you :D And don't forget about the blog posts on CampaignMonitor, which also includes some nice tips. – Horst Gutmann Jan 28 '11 at 14:32
43

Mail chimp have got quite a nice article on what not to do. ( I know it sounds the wrong way round for what you want)

http://kb.mailchimp.com/article/common-html-email-coding-mistakes

In general all the things that you have learnt that are bad practise for web design seem to be the only option for html email.

The basics are:

  • Have absolute paths for images (eg. https://stackoverflow.com/random-image.png)
  • Use tables for layout (never thought I'd recommend that!)
  • Use inline styles (and old school css too, at the very most 2.1, box-shadow won't work for instance ;) )

Just test in as many email clients as you can get your hands on, or use Litmus as someone else suggested above! (credit to Jim)

EDIT :

Mail chimp have done a great job by making this tool available to the community.

It applies your CSS classes to your html elements inline for you!

Community
  • 1
  • 1
SamMullins
  • 267
  • 4
  • 9
  • 1
    the mailchimp link is broken, perhaps it's one of these articles, http://kb.mailchimp.com/article/common-html-email-coding-mistakes or this http://kb.mailchimp.com/article/common-mistakes-to-avoid/ – Nathan Koop Dec 19 '12 at 19:33
  • I've updated the link, the first one you've suggested was the correct one. Unfortunately it was moved without adding redirects. – SamMullins Dec 21 '12 at 11:52
  • Thanks for the CSS inlining tool. Would be helpful I guess. – Rajesh Paul Aug 27 '17 at 18:49
11

In addition to the answers posted here, make sure you read this article:

http://24ways.org/2009/rock-solid-html-emails

Stephan Muller
  • 27,018
  • 16
  • 85
  • 126
6

The resource I always end up going back to about HTML emails is CampaignMonitor's CSS guide.

As their business is geared solely around email delivery, they know their stuff as well as anyone is going to

Gareth
  • 133,157
  • 36
  • 148
  • 157
5

'Fraid so. I'd make an HTML page with a stylesheet, then use jQuery to apply the stylesheet to the style attr of each element. Something like this:

var styleAttributes = ['color','font-size']; // all the attributes you've applied in your stylesheet
for (i in styleAttributes) {
    $('body *').css(styleAttributes[i],function () {
        $(this).css(styleAttributes[i]);
    });
}

Then copy the DOM and use that in the email.

Nathan MacInnes
  • 11,033
  • 4
  • 35
  • 50
  • 2
    You have to be a bit careful with it though... it ain't foolproof. Like it might mess up widths of things, so just check everything before sending. – Nathan MacInnes Jan 28 '11 at 15:00
  • to get around that problem, you can hide the entire document with jQuery first, then run this code (and maybe unhide) - this way the actual CSS rules are retrieved and applied rather than the computed result (eg. for widths.) – majick May 18 '16 at 05:37
1

I find that image mapping works pretty well. If you have any headers or footers that are images make sure that you apply a bgcolor="fill in the blank" because outlook in most cases wont load the image and you will be left with a transparent header. If you at least designate a color that works with the over all feel of the email it will be less of a shock for the user. Never try and use any styling sheets. Or CSS at all! Just avoid it.

Depending if you're copying content from a word or shared google Doc be sure to (command+F) Find all the (') and (") and replace them within your editing software (especially dreemweaver) because they will show up as code and it's just not good.

ALT is your best friend. use the ALT tag to add in text to all your images. Because odds are they are not going to load right. And that ALT text is what gets people to click the (see images) button. Also define your images Width, Height and make the boarder 0 so you dont get weird lines around your image.

Consider editing all images within Photoshop with a 15px boarder on each side (make background transparent and save as a PNG 24) of image. Sometimes the email clients do not read any padding styles that you apply to the images so it avoids any weird formatting!

Also i found the line under links particularly annoying so if you apply < style="text-decoration:none; color:#whatever color you want here!" > it will remove the line and give you the desired look.

There is alot that can really mess with the over all look and feel.

likeitlikeit
  • 5,563
  • 5
  • 42
  • 56
Stephen
  • 1
  • 2