<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>Kevin &#34;Skwerl&#34; Cogill &#187; HTML</title>
	<atom:link href="http://iamskwerl.com/tag/html/feed/" rel="self" type="application/rss+xml" />
	<link>http://iamskwerl.com</link>
	<description>I would never call what I do &#34;hacking.&#34;</description>
	<lastBuildDate>Fri, 30 Dec 2011 17:16:11 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.3</generator>
		<item>
		<title>HTML Emails, Outlook And Background Images</title>
		<link>http://iamskwerl.com/tech/2011/11/html-emails-outlook-and-background-images/</link>
		<comments>http://iamskwerl.com/tech/2011/11/html-emails-outlook-and-background-images/#comments</comments>
		<pubDate>Mon, 28 Nov 2011 21:39:50 +0000</pubDate>
		<dc:creator>Skwerl</dc:creator>
				<category><![CDATA[Technical]]></category>
		<category><![CDATA[CSS]]></category>
		<category><![CDATA[Email]]></category>
		<category><![CDATA[Hacks]]></category>
		<category><![CDATA[HTML]]></category>
		<category><![CDATA[Outlook]]></category>
		<category><![CDATA[VML]]></category>

		<guid isPermaLink="false">http://iamskwerl.com/?p=172</guid>
		<description><![CDATA[Coding HTML for emails can be a total bitch. I&#8217;m not going to give an exhaustive how-to here, but I just wanted to share a few tricks I had to learn the hard way, in case it might save you some headaches. First, a few general rules. These rules will occasionally need to be broken, [...]]]></description>
			<content:encoded><![CDATA[<p>Coding HTML for emails can be a total bitch. I&#8217;m not going to give an exhaustive how-to here, but I just wanted to share a few tricks I had to learn the hard way, in case it might save you some headaches.</p>
<p>First, a few general rules. These rules will occasionally need to be broken, but if you start off by at least <em>trying</em> to follow them, you&#8217;ll give yourself a more stable foundation.</p>
<ul>
<li>Host all of your images online (or via a CDN/S3) and use absolute URLs. Of course.</li>
<li>Use old-school tables to position all of your elements. I know you spent a lot of time weaning yourself off them and mastering div tags positioned with CSS, but email clients rarely handle that stuff properly. For email, we&#8217;ve gotta take it all back to 1998.</li>
<li>When you do use CSS (which is by no means recommended against), put your styles either in-line, or in the body tag. Many email clients will chuck your head tag completely.</li>
<li>Set alt attributes for all of your images and links. I&#8217;ve seen email clients discard images and links that didn&#8217;t have alt attributes.</li>
<li>Explicitly setting border-collapse on your tables to collapse with CSS seems to help kill certain table spacing-related quirks.</li>
<li><a href="http://validator.w3.org/" target="_blank">Validate your HTML</a> at w3.org. Get it as close to perfectly valid as possible (necessary hacks may make perfect validity impossible).</li>
</ul>
<p>Now there&#8217;s one thing in particular that has given me an extraordinary amount of hell when doing HTML emails, and that is background images. Particularly when it comes to Outlook&#8217;s nasty habit of chucking them.</p>
<p>If you&#8217;re okay with having one big background image behind everything, you can apply a background image via CSS to the body tag. That actually works in Outlook. However, put your CSS inline or within the body tag (see above). I&#8217;ve also heard that you need to set repeat-y if you go this route; that setting CSS background-repeat to no-repeat will actually lose the background image completely in Outlook. Not sure if that&#8217;s always the case or what.</p>
<p>The holy grail here is applying background images to table cells. It doesn&#8217;t really work in Outlook. There is, however, a hack that I&#8217;ve found, and that is the main thing I wanted to share here today:</p>
<div class="codecolorer-container html4strict default" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;"><table cellspacing="0" cellpadding="0"><tbody><tr><td style="padding:5px;text-align:center;color:#888888;background-color:#EEEEEE;border-right: 1px solid #9F9F9F;font: normal 12px/1.4em Monaco, Lucida Console, monospace;"><div>1<br />2<br />3<br />4<br />5<br />6<br />7<br />8<br />9<br />10<br />11<br />12<br />13<br />14<br />15<br />16<br />17<br />18<br />19<br />20<br />21<br />22<br /></div></td><td><div class="html4strict codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">table</span> <span style="color: #000066;">width</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;600&quot;</span> <span style="color: #000066;">border</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;0&quot;</span> <span style="color: #000066;">cellpadding</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;0&quot;</span> <span style="color: #000066;">cellspacing</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;0&quot;</span> <span style="color: #000066;">style</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;border-collapse: collapse;&quot;</span>&gt;</span><br />
<span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">tr</span>&gt;</span><br />
&nbsp; &nbsp; <span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">td</span> <span style="color: #000066;">style</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;width: 600px; height: 350px; background-image: url('http://epicreviewsdotorg.files.wordpress.com/2011/05/unicorn1.jpg');&quot;</span>&gt;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #808080; font-style: italic;">&lt;!--[if gte mso 9]&gt;</span><br />
<span style="color: #808080; font-style: italic;">&nbsp; &nbsp; &nbsp; &nbsp; &lt;v:image xmlns:v=&quot;urn:schemas-microsoft-com:vml&quot; id=&quot;theImage&quot; style='behavior: url(#default#VML); display: inline-block; position: absolute; width: 600px; height: 350px; top: 0; left: 0; border: 0; z-index: 1;' src=&quot;http://epicreviewsdotorg.files.wordpress.com/2011/05/unicorn1.jpg&quot; /&gt;</span><br />
<span style="color: #808080; font-style: italic;">&nbsp; &nbsp; &nbsp; &nbsp; &lt;v:shape xmlns:v=&quot;urn:schemas-microsoft-com:vml&quot; id=&quot;theText&quot; style='behavior: url(#default#VML); display: inline-block; position: absolute; width: 600px; height: 350px; top: -5; left: -10; border: 0; z-index: 2;'&gt;</span><br />
<span style="color: #808080; font-style: italic;">&nbsp; &nbsp; &nbsp; &nbsp; &lt;div&gt;</span><br />
<span style="color: #808080; font-style: italic;">&nbsp; &nbsp; &nbsp; &nbsp; &lt;![endif]--&gt;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">table</span> <span style="color: #000066;">width</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;600&quot;</span> <span style="color: #000066;">border</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;0&quot;</span> <span style="color: #000066;">cellspacing</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;0&quot;</span> <span style="color: #000066;">cellpadding</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;0&quot;</span> <span style="color: #000066;">style</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;border-collapse: collapse;&quot;</span>&gt;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">tr</span>&gt;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">td</span> <span style="color: #000066;">height</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;350&quot;</span> <span style="color: #000066;">align</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;center&quot;</span> <span style="color: #000066;">valign</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;top&quot;</span>&gt;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">p</span>&gt;</span>This table in here has a bunch of stuff I want to lay over the background image...<span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span><span style="color: #000000; font-weight: bold;">p</span>&gt;</span> &nbsp; &nbsp; &nbsp; &nbsp; <br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span><span style="color: #000000; font-weight: bold;">td</span>&gt;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span><span style="color: #000000; font-weight: bold;">tr</span>&gt;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span><span style="color: #000000; font-weight: bold;">table</span>&gt;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #808080; font-style: italic;">&lt;!--[if gte mso 9]&gt;</span><br />
<span style="color: #808080; font-style: italic;">&nbsp; &nbsp; &nbsp; &nbsp; &lt;/div&gt;</span><br />
<span style="color: #808080; font-style: italic;">&nbsp; &nbsp; &nbsp; &nbsp; &lt;/v:shape&gt;</span><br />
<span style="color: #808080; font-style: italic;">&nbsp; &nbsp; &nbsp; &nbsp; &lt;![endif]--&gt;</span><br />
&nbsp; &nbsp; <span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span><span style="color: #000000; font-weight: bold;">td</span>&gt;</span><br />
<span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span><span style="color: #000000; font-weight: bold;">tr</span>&gt;</span><br />
<span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span><span style="color: #000000; font-weight: bold;">table</span>&gt;</span></div></td></tr></tbody></table></div>
<p>Outlook can&#8217;t (or refuses to) render basic CSS, but it <em>does</em> know VML (Vector Markup Language), which is what Microsoft Office uses to position elements in Word and Powerpoint. So what we&#8217;re doing is targeting Outlook specifically, and hitting it with some VML.</p>
]]></content:encoded>
			<wfw:commentRss>http://iamskwerl.com/tech/2011/11/html-emails-outlook-and-background-images/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>

