Slicing Images into HTML for Email

Many clients ask us how to slice an image and put it into an email message. This is a good technique if you need to link different parts of the images to different web pages. Below you'll find directions for how to insert sliced images into an HTML email and avoid the most common issues.

Let's take a look at our sample email design, and see how to convert this image into an email message with sliced images and a table structure.

 

 

There are two issues you should avoid when slicing an image for an HTML email.

Issue #1: Arbitrarily Slicing the Image

The image below displays the sample email with slices. At first glance, we have captured all the important hot spots of the design. Every area that we would like to hyperlink has been selected. This is a common mistake made when the slices are cut without considering how it will fit in our HTML.

Every area designated with white icons on a blue background are the slices that we have selected. Notice there are additional areas designated with white icons and grey backgrounds. These are slices that are auto generated by the application. Although we have selected 18 areas, upon exporting this file there will be 43 image files with almost none of them being in the same column or row. Even the most skilled coder would have a hard time making it display across a number of email clients. Not to mention forty three ALT tag descriptions.

Issue #2: Auto Generating HTML in Photoshop

With applications like Photoshop, you can auto generate HTML and image assets. This would be an incredible feature if we were designing a webpage, but email clients are not as forgiving as modern web browsers.  

Lets take a look at the code block below. Notice that application generates one large table with COLSPAN and/or ROWSPAN in virtually every TD. This table is very complex because of the slices added haphazardly, as shown in Issue #1.

Auto generated HTML with image slices
<table border="0" cellpadding="0" cellspacing="0" height="1101" id="Table_01" width="769">
  <tbody>
    <tr>
      <td colspan="15"><img alt="" height="33" src="1b_01.png" width="768"></td>
      <td><img alt="" height="33" src="spacer.gif" width="1"></td>
    </tr>
    <tr>
      <td colspan="2" rowspan="5"><img alt="" height="676" src="1b_02.png" width="45"></td>
      <td colspan="6" rowspan="2"><img alt="" height="88" src="1b_03.png" width="330"></td>
      <td colspan="7"><img alt="" height="17" src="1b_04.png" width="393"></td>
      <td><img alt="" height="17" src="spacer.gif" width="1"></td>
    </tr>
    <tr>
      <td colspan="4" rowspan="3"><img alt="" height="117" src="1b_05.png" width="119"></td>
      <td colspan="3"><img alt="" height="71" src="1b_06.png" width="274"></td>
      <td><img alt="" height="71" src="spacer.gif" width="1"></td>
    </tr>
    <tr>
      <td colspan="6"><img alt="" height="41" src="1b_07.png" width="330"></td>
      <td colspan="3" rowspan="2"><img alt="" height="46" src="1b_08.png" width="274"></td>
      <td><img alt="" height="41" src="spacer.gif" width="1"></td>
    </tr>
    <tr>
      <td rowspan="2"><img alt="" height="547" src="1b_09.png" width="3"></td>
      <td colspan="3" rowspan="2"><img alt="" height="547" src="1b_10.png" width="204"></td>
      <td colspan="2"><img alt="" height="5" src="1b_11.png" width="123"></td>
      <td><img alt="" height="5" src="spacer.gif" width="1"></td>
    </tr>
    <tr>
      <td><img alt="" height="542" src="1b_12.png" width="26"></td>
      <td colspan="4"><img alt="" height="542" src="1b_13.png" width="203"></td>
      <td colspan="2"><img alt="" height="542" src="1b_14.png" width="19"></td>
      <td><img alt="" height="542" src="1b_15.png" width="200"></td>
      <td rowspan="2"><img alt="" height="561" src="1b_16.png" width="68"></td>
      <td><img alt="" height="542" src="spacer.gif" width="1"></td>
    </tr>
    <tr>
      <td colspan="14" rowspan="2"><img alt="" height="39" src="1b_17.png" width="700"></td>
      <td><img alt="" height="19" src="spacer.gif" width="1"></td>
    </tr>
    <tr>
      <td rowspan="9"><img alt="" height="122" src="1b_18.png" width="68"></td>
      <td><img alt="" height="20" src="spacer.gif" width="1"></td>
    </tr>
    <tr>
      <td colspan="14"><img alt="" height="12" src="1b_19.png" width="700"></td>
      <td><img alt="" height="12" src="spacer.gif" width="1"></td>
    </tr>
    <tr>
      <td rowspan="12"><img alt="" height="340" src="1b_20.png" width="9"></td>
      <td colspan="3" rowspan="5"><img alt="" height="80" src="1b_21.png" width="82"></td>
      <td colspan="10"><img alt="" height="9" src="1b_22.png" width="609"></td>
      <td><img alt="" height="9" src="spacer.gif" width="1"></td>
    </tr>
    <tr>
      <td rowspan="7"><img alt="" height="142" src="1b_23.png" width="18"></td>
      <td colspan="2"><img alt="" height="20" src="1b_24.png" width="169"></td>
      <td colspan="5"><img alt="" height="20" src="1b_25.png" width="216"></td>
      <td colspan="2"><img alt="" height="20" src="1b_26.png" width="206"></td>
      <td><img alt="" height="20" src="spacer.gif" width="1"></td>
    </tr>
    <tr>
      <td colspan="2"><img alt="" height="23" src="1b_27.png" width="169"></td>
      <td colspan="5"><img alt="" height="23" src="1b_28.png" width="216"></td>
      <td colspan="2"><img alt="" height="23" src="1b_29.png" width="206"></td>
      <td><img alt="" height="23" src="spacer.gif" width="1"></td>
    </tr>
    <tr>
      <td colspan="2"><img alt="" height="23" src="1b_30.png" width="169"></td>
      <td colspan="5"><img alt="" height="23" src="1b_31.png" width="216"></td>
      <td colspan="2"><img alt="" height="23" src="1b_32.png" width="206"></td>
      <td><img alt="" height="23" src="spacer.gif" width="1"></td>
    </tr>
    <tr>
      <td colspan="9" rowspan="2"><img alt="" height="11" src="1b_33.png" width="591"></td>
      <td><img alt="" height="5" src="spacer.gif" width="1"></td>
    </tr>
    <tr>
      <td colspan="3" rowspan="3"><img alt="" height="71" src="1b_34.png" width="82"></td>
      <td><img alt="" height="6" src="spacer.gif" width="1"></td>
    </tr>
    <tr>
      <td colspan="5" rowspan="2"><img alt="" height="65" src="1b_35.png" width="347"></td>
      <td colspan="4" rowspan="2"><img alt="" height="65" src="1b_36.png" width="244"></td>
      <td><img alt="" height="4" src="spacer.gif" width="1"></td>
    </tr>
    <tr>
      <td rowspan="2"><img alt="" height="126" src="1b_37.png" width="68"></td>
      <td><img alt="" height="61" src="spacer.gif" width="1"></td>
    </tr>
    <tr>
      <td rowspan="4"><img alt="" height="189" src="1b_38.png" width="36"></td>
      <td colspan="7" rowspan="2"><img alt="" height="172" src="1b_39.png" width="374"></td>
      <td colspan="5" rowspan="3"><img alt="" height="181" src="1b_40.png" width="281"></td>
      <td><img alt="" height="65" src="spacer.gif" width="1"></td>
    </tr>
    <tr>
      <td rowspan="3"><img alt="" height="124" src="1b_41.png" width="68"></td>
      <td><img alt="" height="107" src="spacer.gif" width="1"></td>
    </tr>
    <tr>
      <td colspan="7" rowspan="2"><img alt="" height="17" src="1b_42.png" width="374"></td>
      <td><img alt="" height="9" src="spacer.gif" width="1"></td>
    </tr>
    <tr>
      <td colspan="5"><img alt="" height="8" src="1b_43.png" width="281"></td>
      <td><img alt="" height="8" src="spacer.gif" width="1"></td>
    </tr>
    <tr>
      <td><img alt="" height="1" src="spacer.gif" width="9"></td>
      <td><img alt="" height="1" src="spacer.gif" width="36"></td>
      <td><img alt="" height="1" src="spacer.gif" width="3"></td>
      <td><img alt="" height="1" src="spacer.gif" width="43"></td>
      <td><img alt="" height="1" src="spacer.gif" width="18"></td>
      <td><img alt="" height="1" src="spacer.gif" width="143"></td>
      <td><img alt="" height="1" src="spacer.gif" width="26"></td>
      <td><img alt="" height="1" src="spacer.gif" width="97"></td>
      <td><img alt="" height="1" src="spacer.gif" width="44"></td>
      <td><img alt="" height="1" src="spacer.gif" width="37"></td>
      <td><img alt="" height="1" src="spacer.gif" width="25"></td>
      <td><img alt="" height="1" src="spacer.gif" width="13"></td>
      <td><img alt="" height="1" src="spacer.gif" width="6"></td>
      <td><img alt="" height="1" src="spacer.gif" width="200"></td>
      <td><img alt="" height="1" src="spacer.gif" width="68"></td>
      <td>&nbsp;</td>
    </tr>
  </tbody>
</table>

 

 The image below shows how this messages displays across email clients.

Email clients will struggle to render so many different columns and rows. In fact, the only content that rendered correctly did not include COLSPAN or ROWSPAN.

Solution: Keep It Simple

When slicing the image file, take care to keep the slices simple, with horizontal rows stretching across the whole width of the image. This image is sliced into exactly 18 areas in a way that we can create the simplest table structure possible while keeping all of the original hot spots.

Slices have been carefully placed to ensure columns and rows line up as much as possible. This is done to minimize the need for spacer images and in this instance we have eliminated the need for them altogether. Also make sure not to overlap slices and ensure each slice borders the next.

In the auto generated table above, we saw that the table had multiple COLSPAN and ROWSPAN declarations throughout the table. Now that we have created a much simpler table, the message will render correctly in most email clients. As a general rule of thumb, we want to nest tables instead of using ROWSPAN and COLSPAN. This is just one additional step that can be taken to ensure our message renders correctly. 

Let's skip the auto generated code and build an outline of the table from the sliced image.

Figure 1.1

Figure 1

Here we have the outline of our table. Now we can add images, hyperlinks, and fill in the ALT tag descriptions to complete the message.

Figure 1.1 codeblock
<!-- Make sure the with of the table is equal to the width of the sliced image. As a rule of thumb, I like to always center my tables in the email window. Also the order of images will be different based on the order they are sliced -->
<table width="768" align="center">
 <tr>
  <td><table>
    <tr>
     <td>image 1</td>
     <td>image 2</td>
    </tr>
   </table></td>
 <tr>
 <tr>
  <td><table>
    <tr>
     <td>image 3</td>
     <td>image 4</td>
     <td>image 5</td>
    </tr>
   </table></td>
 </tr>
 <tr>
  <td><table>
    <tr>
     <td><table>
       <tr>
        <td>image 6</td>
       </tr>
       <tr>
        <td><table>
          <tr>
           <td>image 7</td>
           <td><table>
             <tr>
              <td>image 8</td>
             </tr>
             <tr>
              <td>image 9</td>
             </tr>
             <tr>
              <td>image 10</td>
             </tr>
            </table></td>
           <td><table>
             <tr>
              <td>image 11</td>
             </tr>
             <tr>
              <td>image 12</td>
             </tr>
             <tr>
              <td>image 13</td>
             </tr>
            </table></td>
           <td><table>
             <tr>
              <td>image 14</td>
             </tr>
             <tr>
              <td>image 15</td>
             </tr>
             <tr>
              <td>image 16</td>
             </tr>
            </table></td>
          </tr>
         </table></td>
       </tr>
      </table></td>
     <td>image 17</td>
    </tr>
   </table></td>
 </tr>
 <tr>
  <td>image 18</td>
 </tr>
</table>
				

Cleaning up

Since nested tables were used, we want to make sure that we removed all borders, margins and padding from the tables to make sure no spaces are created between the images. In this case, we have added the following attributes and styles to all table tags within the message.

border="0" cellpadding="0" cellspacing="0" style="border: 0; margin: 0; padding: 0;"

Finally we want to add an inline styles to all <img> tags to prevent gaps below any of our images. 

style="display: block;"

We end up with the resulting code:

Using nested tables
<table align="center" border="0" cellpadding="0" cellspacing="0" style="border: 0; margin: 0; padding: 0;" width="768">
  <tbody>
   <tr>
    <td>
    <table border="0" cellpadding="0" cellspacing="0" style="border: 0; margin: 0; padding: 0;">
     <tbody>
      <tr>
      <td><img align="left" alt="" height="143" src=" 1_01.png" style="display: block;" width="466"></td>
      <td><img align="left" alt="" height="143" src=" 1_02.png" style="display: block;" width="302"></td>
      </tr>
     </tbody>
    </table>
    </td>
   </tr>
   <tr>
    <td>
    <table border="0" cellpadding="0" cellspacing="0" style="border: 0; margin: 0; padding: 0;">
     <tbody>
      <tr>
      <td><img align="left" alt="" height="566" src=" 1_03.png" style="display: block;" width="278"></td>
      <td><img align="left" alt="" height="566" src=" 1_04.png" style="display: block;" width="216"></td>
      <td><img align="left" alt="" height="566" src=" 1_05.png" style="display: block;" width="274"></td>
      </tr>
     </tbody>
    </table>
    </td>
   </tr>
   <tr>
    <td>
    <table border="0" cellpadding="0" cellspacing="0" style="border: 0; margin: 0; padding: 0;">
     <tbody>
      <tr>
      <td>
       <table border="0" cellpadding="0" cellspacing="0" style="border: 0; margin: 0; padding: 0;">
        <tbody>
        <tr>
         <td><img align="left" alt="" height="39" src=" 1_06.png" style="display: block;" width="700"></td>
        </tr>
        <tr>
         <td>
          <table border="0" cellpadding="0" cellspacing="0" style="border: 0; margin: 0; padding: 0;">
          <tbody>
           <tr>
            <td><img align="left" alt="" height="102" src=" 1_08.png" style="display: block;" width="109"></td>
            <td>
            <table border="0" cellpadding="0" cellspacing="0" style="border: 0; margin: 0; padding: 0;">
             <tbody>
              <tr>
              <td><img align="left" alt="" height="41" src=" 1_09.png" style="display: block;" width="169"></td>
              </tr>
              <tr>
              <td><img align="left" alt="" height="23" src=" 1_12.png" style="display: block;" width="169"></td>
              </tr>
              <tr>
              <td><img align="left" alt="" height="38" src=" 1_15.png" style="display: block;" width="169"></td>
              </tr>
             </tbody>
            </table>
            </td>
            <td>
            <table border="0" cellpadding="0" cellspacing="0" style="border: 0; margin: 0; padding: 0;">
             <tbody>
              <tr>
              <td><img align="left" alt="" height="41" src=" 1_10.png" style="display: block;" width="216"></td>
              </tr>
              <tr>
              <td><img align="left" alt="" height="23" src=" 1_13.png" style="display: block;" width="216"></td>
              </tr>
              <tr>
              <td><img align="left" alt="" height="38" src=" 1_16.png" style="display: block;" width="216"></td>
              </tr>
             </tbody>
            </table>
            </td>
            <td>
            <table border="0" cellpadding="0" cellspacing="0" style="border: 0; margin: 0; padding: 0;">
             <tbody>
              <tr>
              <td><img align="left" alt="" height="41" src=" 1_11.png" style="display: block;" width="206"></td>
              </tr>
              <tr>
              <td><img align="left" alt="" height="23" src=" 1_14.png" style="display: block;" width="206"></td>
              </tr>
              <tr>
              <td><img align="left" alt="" height="38" src=" 1_17.png" style="display: block;" width="206"></td>
              </tr>
             </tbody>
            </table>
            </td>
           </tr>
          </tbody>
          </table>
         </td>
        </tr>
        </tbody>
       </table>
      </td>
      <td><img align="left" alt="" height="141" src=" 1_07.png" style="display: block;" width="68"></td>
      </tr>
     </tbody>
    </table>
    </td>
   </tr>
   <tr>
    <td><img align="left" alt="" height="250" src=" 1_18.png" style="display: block;" width="768"></td>
   </tr>
 </tbody>
</table>

Despite all of our efforts, we open the message and see this:

This is one of the drawbacks of slicing images for email campaigns: if the email client blocks images by default, the subscriber will have to click to download the images.

Mobile version

When slicing images for an email campaign there is a very good chance you will need an entirely different image for your mobile version. If the image you slice contains any photographic elements such as pictures and backgrounds, scaling down the content will result in a loss of image quality. If your design consists of only vector based graphics; using width percentages, and nested tables as described above will enable you to scale down your desktop version for mobile devices. 

Our sample design is graphic heavy so we will use our alternate mobile design. 

  

Here is the sliced image created using the sample principles from our desktop version.

Notice that there is one area that we did not create a slice.  In this case, we can create a table to display the text since this section is text only on a plain navy background. 

Mobile version with nested tables using %'s
<table width="320" border="0" cellpadding="0" cellspacing="0" align="center">
  <tr>
    <td colspan="3"><a href="#"><img src="01.png" alt="Skyline Travel" width="100%" border="0"></a></td>
  </tr>
  <tr>
    <td colspan="3"><a href="#"><img src="02.png" alt="View All Deals" width="100%" border="0"></a></td>
  </tr>
  <tr>
    <td width="33%" valign="bottom" style="background: #4884e5;"><a href="#"><img src="03.png" alt="Hawaii" width="100%" border="0"></a></td>
    <td width="34%" valign="bottom" style="background: #4884e5;"><a href="#"><img src="04.png" alt="Canada" width="100%" border="0"></a></td>
    <td width="33%" valign="bottom" style="background: #4884e5;"><a href="#"><img src="05.png" alt="Canada" width="100%" border="0"></a></td>
  </tr>
  <tr>
    <td colspan="3" style="background: #222534; padding:.4em;"><table width="100%" border="0" cellpadding="0" cellspacing="2" style="font-family: Arial, sans-serif; font-size: .9em; color: #fff;">
        <tr>
          <td style="padding-left: .4em;"><a href="#" style="color: #fff; text-decoration: underline; font-weight: bold;" title="Flight to Canada from $79">Canada $79</a></td>
          <td style="padding-left: .4em;"><a href="#" style="color: #fff; text-decoration: underline; font-weight: bold;" title="Flight to South America from $79">South America $129</a></td>
        </tr>
        <tr>
          <td style="padding-left: .4em;"><a href="#" style="color: #fff; text-decoration: underline; font-weight: bold;" title="Flight to Mexico from $79">Mexico $79</a></td>
          <td style="padding-left: .4em;"><a href="#" style="color: #fff; text-decoration: underline; font-weight: bold;" title="Flight to Puerto Rico from $129">Puerto Rico $129</a></td>
        </tr>
        <tr>
          <td style="padding-left: .4em;"><a href="#" style="color: #fff; text-decoration: underline; font-weight: bold;" title="Domestic flight from $59">Domestic from $59</a></td>
          <td style="padding-left: .4em;"><a href="#" style="color: #fff; text-decoration: underline; font-weight: bold;" title="Flight to Canada from $79">Jamaica $129</a></td>
        </tr>
        <tr>
          <td style="padding-left: .4em;"><a href="#" style="color: #fff; text-decoration: underline; font-weight: bold;" title="Flight to Japan from $229">Japan $229</a></td>
          <td style="padding-left: .4em;"><a href="#" style="color: #fff; text-decoration: underline; font-weight: bold;" title="Flight to Hong Kong from $249">Hong kong $249</a></td>
        </tr>
        <tr>
          <td colspan="2" style="padding-left: .4em;"><a href="#" style="color: #fff; text-decoration: underline; font-weight: bold;">Fiji $299</a></td>
        </tr>
      </table></td>
  </tr>
  <tr>
    <td colspan="3"><img src="07.png" alt="London $99" width="100%" border="0"></td>
  </tr>
</table>

The mobile version renders on our mobile device below.