Developing emails for Gmail

Developing HTML Emails for Gmail: 12 Things You Must Know


This post was updated on April 12, 2018. It was last updated in March 2017 and originally published in June 2013.

Many email developers know how tricky it is to develop HTML emails for Gmail – it’s one of the more temperamental clients out there (although it’s no Outlook).

Remembering to test your email can help you catch some of these problem areas, and starting with the right code and some knowledge will help, too. It’s also important to look at your email analytics to find out how many of your subscribers use Gmail. Luckily, Email on Acid can help you do both.

If you find yourself coding for Gmail users, here are a few things to keep in mind:

  1. Gmail has several email clients.
  2. Gmail app for non-Google accounts (GANGA) does not support background images.
  3. Gmail clips your messages larger than 102Kb.
  4. Gmail only supports <style> in the <head>
  5. Gmail removes your entire <style> block if it encounters an error.
  6. Gmail displays preheader text in the subject line.
  7. Gmail does not support attribute selectors and most pseudo-classes.
  8. Gmail displays an image download icon over large unlinked images.
  9. Gmail does not allow negative CSS margin values.
  10. Gmail automatically converts phone numbers and URLs to links.
  11. Gmail uses the HTML5 DOCTYPE.
  12. Gmail’s DOCTYPE can create extra space under images.

1. Gmail has several email clients.

Although many people most often associate Gmail with webmail and mobile apps, Gmail has many different versions and incarnation. This includes Gmail’s inbox client, G Suite for businesses, as well as a particularly problematic version of their Android client that’s configured for POP/IMAP access (see tip #2 for more information).

Want to learn more? Check out this article from Remi Parmentier has published an article on the different Gmail clients.

2. Gmail app for non-Google accounts (GANGA) does not support background images.

The Gmail Android app that comes pre-installed with most new Android phones contains a feature to access non-Google accounts using POP and IMAP. Unfortunately, emails accessed through this setup lack the embedded style (<style>) support as well as the support for background images.

As of December 2017, the iOS Gmail app also supports IMAP accounts. However, like the Android app, the iOS version does not support embedded CSS or the style tag.

3. Gmail clips messages larger than 102kB.

If your email’s size exceeds 102kB, Gmail will display the first 102kB along with a message that reads:

[Message clipped]  View entire message

When the user clicks to view the entire message, your email will be displayed in a new window.

If you’re close to 102kB, you can save a few bytes by removing any unnecessary spaces, carriage returns or comments. You also want to avoid embedded images and documents when sending HTML emails.

4. Gmail only supports <style> in the <head>.

Gmail does support embedded styles (<style>). However, embedded styles are only supported in the head of your HTML document. The Gmail Android and iOS apps does not support <style> at all when rendering emails retrieved through non-Google accounts (GANGA).

5. Gmail removes your entire <style> block if it encounters an error.

Gmail is very finicky when it comes to parsing embedded styles. If it encounters even one error, it throws away the entire block.

For example, Gmail does not like an ‘@’ declaration within an ‘@’ declaration. One way to deal with this is to use multiple style blocks and put the styles that are Gmail safe in the top block.

@media only screen and (max-width:320px) { @viewport { width:320px; } }

Gmail also eliminates your style block if it exceeds 8192 characters.

If your style block exceeds 8192 characters, split it into two parts. Gmail will remove the first block that exceeds the 8192-character threshold and any blocks after it (the character count includes all of your style blocks).

6. Gmail displays preheader text in the email preview.

Like many modern clients, the email preheader is automatically shown after the subject without the recipient having to open the email message. Preheader text can be a visible part of your email body or it can be specially crafted to only display before the subscriber opens your email (hidden preheaders). This article explains how to code hidden preheaders.

7. Gmail does not support attribute selectors and most pseudo-classes.

Attribute selectors (like the one below) allow for a more flexibility when selecting of elements in CSS. Although they are supported in modern email clients such as iOS and Apple Mail, Gmail does not support them.

div[class="content"]{ color: red }

Gmail also does not support pseudo-classes like :checked and :active and only supports :hover in their webmail client. Therefore, interactive email support in Gmail is very limited or non-existent.

Gmail did announce in early 2018 that it will be rolling out Accelerated Mobile Pages (AMP) for Email, which will allow for fully interactive emails in Gmail.

8. Gmail displays an image download icon over large unlinked images.

Gmail will overlay an icon that lets recipients download images that are not wrapped with a URL. This can be frustrating to designers who would rather Gmail not mess when their email designs.

The simplest solution is to ensure that images larger than 300×150 are wrapped with a link, but there are several other options you can try.

9. Gmail does not allow negative CSS margin values.

Most webmail clients such as Outlook.com and Yahoo! Mail do not allow negative margin values and Gmail is no exception.

10. Gmail automatically converts phone numbers and URLs to links.

Both the desktop and mobile versions of Gmail now insert an anchor link around phone numbers. In the desktop version, the link opens Google’s new voice/chat console which is displayed along the right column of the Gmail interface.

To block this, use an HTML entity in your phone number that Gmail does not recognize such as “&#173;”

&#173;212&#173;-389&#173;-3934

In the above example, we inserted this entity before each dash.

Check out this article for more examples and fixes.

If you have a URL or email address listed without a link, Gmail will add it for you. For example, Gmail will convert name@test.com within this paragraph will get converted to:

<a href=“mailto:name@test.com”> name@test.com</a>

Here are two potential fixes:

1.) Insert an HTML entity that Gmail does not recognize, like:

&#173;

Which means you should change name@test.com to:

name@test­&#173;.com

Change www.mydomain.com to:

www.mydomain­&#173;.com

Change http://www.mydomain.com to:

http:&#173;­//www.mydomain­&#173;.com

2.) Insert an anchor around the URL or email address and format it like the rest of your text. For example:

<a href=’#’ style=“color:#000; text-decoration:none”> test@test.com</a>

11. Gmail uses the HTML5 DOCTYPE.

Regardless of the DOCTYPE specified in your email, the email will be rendered using the HTML5 DOCTYPE in Gmail. This may cause your email to render differently than if you loaded your email in a browser.

12. Gmail’s DOCTYPE can create extra space under images.

This space is also caused by the DOCTYPE. Here are a few workarounds (these work in Outlook.com and Yahoo! Beta, as well):

1.) Add style display:block to the image element

<img src=“test.jpg” style=“display:block”>

2.) Add align absbottom in the image element

<img src=“test.jpg” align=“absbottom”>

3.) Add align texttop to the image element

<img src=“test.jpg” align=” texttop ”>

4.) Add line-height 10px or lower in the containing TD

<td style=“line-height:10px”>

5.) Add font-size 6px or lower in the containing TD

<td style=“font-size:6px”>

For more workarounds, check out this blog article: 12 Fixes for Image Spacing

Do You Have Other Gmail Tips?

If you have any other tricks or workarounds for Gmail, feel free to share them in the comments section below! Or, you can hit us up on Facebook or Twitter.

But remember, even with these workarounds, it is still important to test your email to make sure it renders correctly in Gmail and all the other major email clients. With Email on Acid, you’ll get unlimited email testing and previews on more than 70 clients and devices. Try our platform free for seven days and see for yourself.

TEST TODAY!

9 thoughts on “Developing HTML Emails for Gmail: 12 Things You Must Know”

  1. Point number 7 is partly wrong, Gmail is reading my attribute styling, is this a new thing?
    This is the CSS that it is reading (and shouldn’t be)
    [class~=fallback] { display:none; }
    [class~=interactive] { height:auto !important; max-height:none !important; display:block !important; font-size:inherit !important; line-height:inherit !important; }
    Got any work arounds?

    1. Hi Al –
      Good question! Support for IDs in email can be spotty, but classes should be there. Gmail may still strip the whole head tag, though, so inline styling is always needed in Gmail. Hope that helps!

  2. Hii,
    I have a question.
    I want to change font of gmail which i use in HTML tag. when i sent a mail to user i want my own font show in to mail, it is possible? if yes then how?
    Please suggest me.
    Thank you.

Leave a Reply

Your email address will not be published. Required fields are marked *

Free Email Goodies