Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Do I need to use spacer images when coding HTML emails?

I understand that HTML emails need to use really old school layouts - as per lots of other answers on SO (e.g. HTML email: tables or divs?, HTML Email using CSS).

However, there seems to be some debate over whether it's still a good idea to use spacer gifs in email.

For example, compare these three layouts:

DIMENSIONS:

<table cellpadding="0" cellspacing="0" border="0" width="100">
  <tr>
    <td width="100" height="10"></td>
  </tr>
</table>

WITH SPACER GIF:

<table cellpadding="0" cellspacing="0" border="0">
  <tr>
    <td><img src="spacer.gif" width="100" height="10"></td>
  </tr>
</table>

WITH SPACER GIF AND DIMENSIONS:

<table cellpadding="0" cellspacing="0" border="0" width="100">
  <tr>
    <td width="100" height="10"><img src="spacer.gif" width="100" height="10"></td>
  </tr>
</table>

How do I use them with dimensions? Are there any email clients that still require spacer gifs? Is there any harm done either way?

like image 891
Dan Blows Avatar asked May 24 '12 06:05

Dan Blows


People also ask

Does padding work in HTML emails?

It is advisable to take the help of HTML padding when you will not need to alter the spacing according to the different screen sizes. While padding is used to add spacing in a <td> cell, margin attribute goes well with <div> tags, when you want to add spacing to <div> elements. .

How do I add spacing in HTML email?

Line Breaks. Using the <br> tag is the simplest way to add space in the email content when coded using HTML in email. This method can be used only to create spacing between the texts in the copy of an email and hence it is not used much. <br> tag can be used before and after the content.

What is spacer image HTML?

A spacer GIF is a small, transparent GIF image that is used in web design and HTML coding. They were used to control the visual layout of HTML elements on a web page, at a time when the HTML standard alone did not allow this.

How do I display an image in HTML email?

To attach an image, you need to have the encoding scheme of the image you want to attach. This is the base64 string of the picture. You can get this by right-clicking on the image you want to attach, copy the image address, and paste it into the HTML text. The recipient will have a preview of when they open the email.


2 Answers

Personally, I never use spacer gifs, because they destroy the layout when image blocking is turned off, for three reasons:

  1. If they don't render at all, any layout that requires the spacer image is lost.
  2. If they render incorrectly (such as reverting to their original size, or proportionally to their original size) they break the layout.
  3. Even if they do render properly and the layout works, all the image placeholders that are displayed when image blocking is turned on distract from the message of the email.

To get around issue #2, you can save each image with its actual dimensions. However, this obviously increases:

  • Time to build
  • Number of images to be downloaded by client

and it doesn't solve issues #1 and #3.

The reason for using spacer gifs is because some clients (Outlook 2007, Outlook 2010, Lotus Notes, Hotmail / Live Mail) will not render an empty cell. It's very difficult to have absolute precision over dimensions of a text node, and so a spacer image suffices. However, even those clients mentioned will render an empty cell that has width defined.

So as long as you're defining pixel widths on any empty cells you are fine. To go back to the examples in the question:

  • Dimensions-only - works with and without image-blocking in all major email clients
  • Spacer images only - works only when image-blocking is turned off
  • Dimensions and spacer images - works only when image-blocking is turned off

Because of this, you should use dimensions and not spacer gifs.

Various articles talk about this question as well (search for 'spacer images' on the pages)

  • http://www.banane.com/workblog/?p=61
  • http://www.campaignmonitor.com/design-guidelines/
like image 132
Dan Blows Avatar answered Sep 22 '22 13:09

Dan Blows


You can definitely avoid using spacer gifs.

I find that the following code works in all clients. I generally either specify the width or the height of these empty cells. This specific example is what I use to create vertical space:

<tr>
 <td style="line-height: 0; font-size: 0;" height="10">&nbsp;</td>
</tr>
like image 45
Nicole Merlin Avatar answered Sep 19 '22 13:09

Nicole Merlin