{"id":483,"date":"2018-09-03T22:06:37","date_gmt":"2018-09-03T22:06:37","guid":{"rendered":"http:\/\/pauldipper.com\/?p=483"},"modified":"2018-10-07T11:59:05","modified_gmt":"2018-10-07T11:59:05","slug":"top-ten-email-coding-tips-by-paul-dipper","status":"publish","type":"post","link":"http:\/\/pauldipper.com\/?p=483","title":{"rendered":"Top Ten Email Coding Tips <br>By Paul Dipper"},"content":{"rendered":"<p class=\"font_8\">Say the words\u00a0\u201cBuild me an email\u201d\u00a0to a developer and watch the expression on their face drop. Yes, HTML emails are old school, but there\u2019s no need to don a loin cloth and start chipping out code from a stone tablet.<\/p>\n<p class=\"font_8\">Email has come on leaps and bounds within the last few years, and with open rates frequently increasing on mobile devices, there are a few tips and tricks you can use\u00a0for responsive emails.<\/p>\n<h3 class=\"font_8\">\nHere are a few favourites to keep you building successful, responsive emails:<\/h3>\n<h4 class=\"font_8\">\u00a01).\u00a0Keep inline<\/h4>\n<p class=\"font_8\">If you have tried building an email before, you have probably heard of this one. This is basically adding any\u00a0style changes\u00a0you make to the containing table of your content.<\/p>\n<p class=\"font_8\">\n<p class=\"font_8\"><strong>For example:<\/strong><\/p>\n<p class=\"font_8\"><em>&lt;td style=&#8221;font-family:Arial, Helvetica, sans-serif; font-size:11px; color:#000000;\u201d&gt;Hello World&lt;\/td&gt;<\/em><\/p>\n<p class=\"font_8\">\nThe main benefit behind using this styling is that some email clients will strip out embedded CSS in the &lt;head&gt;, leaving your email with as much style as socks and sandals.<\/p>\n<p class=\"font_8\">\nEmail developers have already started trialing emails with no inline CSS, which are not 100% foolproof yet, but with a large percentage of global email clients supporting embedded CSS, there is hope for cleaner emails in the future.<\/p>\n<p class=\"font_8\">\n<h4 class=\"font_8\">2). Query your media<\/h4>\n<p class=\"font_8\">Let\u2019s say you want that image smaller, or a different font for that block of text, or you need that column to stack on mobile\u2026 not a problem! Media query to the rescue. \u00a0Media queriesare the CSS3 commands that allow you to change your viewpoint depending on your screen resolution, \u00a0meaning that your imagery and content will display differently on different devices&#8230; thus making your content fully responsive.<\/p>\n<p class=\"font_8\">Within the &lt;head&gt; of any email there will be a minimum width set, for instance 480px which will control and sometimes constrain how your media is displayed. \u00a0But, if you add a media query to your style command, any styles that you set within that media query will take over when the screen resolution drops below the minimum width.<\/p>\n<p class=\"font_8\"><strong>For example:<\/strong><\/p>\n<p class=\"font_8\"><em>&lt;style type=&#8221;text\/css&#8221;&gt;<\/em><\/p>\n<p class=\"font_8\"><em>\u00a0\u00a0 \u00a0body {width: 680px; \u00a0background-color:#000000;}<\/em><\/p>\n<p class=\"font_8\"><em>\u00a0\u00a0 \u00a0@media only screen and (max-width:480px)\u00a0{<\/em><br \/>\n<em>\u00a0\u00a0 \u00a0\u00a0\u00a0\u00a0\u00a0body {width:100% !important; \u00a0background-color:#ffffff !important;}<\/em><br \/>\n<em>\u00a0\u00a0 \u00a0}<\/em><\/p>\n<p class=\"font_8\"><em>&lt;\/style&gt;<\/em><\/p>\n<p class=\"font_8\">\nThis means your image can be any size, the font family can styled differently for each resolution, and you can stack your columns all day long. Happy days!<\/p>\n<p>&nbsp;<\/p>\n<h4 class=\"font_8\">3). Stacking<\/h4>\n<p class=\"font_8\">We briefly mentioned stacking columns in the last tip. \u00a0As you&#8217;d expect, this coding command allows you to stack columns on top of one another\u00a0by setting them as\u00a0.stackonmobile {display:block;}\u00a0for mobile. This coding tip helps with\u00a0mobile optimisation\u00a0by making sections of your email more visible and legible on smaller screen resolutions, instead of trying to squash them into one column.<\/p>\n<p class=\"font_8\">\nThe default for stacking was left to right for a long time, however more recently we can now\u00a0reverse stack, by setting the containing tables text direction as right to left.<\/p>\n<p class=\"font_8\"><strong>For example:<\/strong><\/p>\n<p class=\"font_8\"><em>&lt;table width=\u201c600\u201d\u00a0dir=\u201crtl\u201d&gt;<\/em><br \/>\n<em>\u00a0\u00a0 \u00a0&lt;tr&gt;<\/em><br \/>\n<em>\u00a0\u00a0 \u00a0\u00a0\u00a0 \u00a0&lt;th width=\u201c300\u201d\u00a0dir=\u201cltr\u201d class=\u201cstackonmobile\u201d&gt;World&lt;\/th&gt;<\/em><br \/>\n<em>\u00a0\u00a0 \u00a0\u00a0\u00a0 \u00a0&lt;th width=\u201c300\u201d\u00a0dir=\u201cltr\u201d class=\u201cstackonmobile\u201d&gt;Hello&lt;\/th&gt;<\/em><br \/>\n<em>\u00a0\u00a0 \u00a0&lt;\/tr&gt;<\/em><br \/>\n<em>&lt;\/table&gt;<\/em><\/p>\n<p class=\"font_8\">\nNote that we need to redirect the sub-tables back to left to right for text alignment. Also the html layout will be reversed, right column first, which is why &#8216;<i>World&#8217;<\/i>\u00a0is before &#8216;Hello&#8217;\u00a0in the example above.<br \/>\nAlso note that we have used &lt;th&gt; instead of &lt;td&gt; for Android compatibility, as they dropped the use of display:block on td\u2019s.\n<\/p>\n<h4 class=\"font_8\">4).\u00a0Min vs Max<\/h4>\n<p class=\"font_8\">With screen resolutions getting bigger and bigger, is it a good idea to make our emails wider?<br \/>\nWhen I started in email builds (back in the dark ages of blackboards and chalk written HTML), the width was 585px. This slowly grew to a standard 600px, which seems to still be the acceptable size. Most of the emails we produce today are anywhere between 600px &amp; 720px. Occasionally a 1000px email rears it\u2019s oversized head, but these are usually for big occasions with large hero images for impact.<\/p>\n<p class=\"font_8\">\nWhat we need to remember is that emails will still be framed by the email clients furniture i.e. the inbox list, the search and edit tools, sender details etc. So an oversized email might end up stretching beyond the width of the screen, which results in an ugly horizontal scroll bar at the bottom\u2026 and nobody wants that.<\/p>\n<p class=\"font_8\">So remember, size does matter. \u00a0Always aim for the optimal image size depending on the platform or\u00a0device being used to ensure your emails remain mobile responsive.<\/p>\n<p>&nbsp;<\/p>\n<h4 class=\"font_8\">5).\u00a0Bring it to the Table<\/h4>\n<p class=\"font_8\">With email development, it\u2019s all about the tables. Below you\u2019ll find an example of an email HTML table.<\/p>\n<p class=\"font_8\">\n<p class=\"font_8\"><strong>Example:<\/strong><br \/>\n<em>&lt;table\u00a0width=\u201c100%\u201d&gt;<\/em><br \/>\n<em>\u00a0\u00a0 \u00a0&lt;tr&gt;<\/em><br \/>\n<em>\u00a0\u00a0 \u00a0&lt;td align=&#8221;center&#8221;&gt;<\/em><br \/>\n<em>\u00a0\u00a0 \u00a0\u00a0\u00a0 \u00a0&lt;table\u00a0width=\u201c700\u201d&gt;<\/em><br \/>\n<em>\u00a0\u00a0 \u00a0\u00a0\u00a0 \u00a0\u00a0\u00a0 \u00a0&lt;tr&gt;<\/em><br \/>\n<em>\u00a0\u00a0 \u00a0\u00a0\u00a0 \u00a0\u00a0\u00a0 \u00a0&lt;td align=&#8221;center&#8221;&gt;<\/em><br \/>\n<em>\u00a0\u00a0 \u00a0\u00a0\u00a0 \u00a0\u00a0\u00a0 \u00a0\u00a0\u00a0 \u00a0&lt;table\u00a0width=\u201c100%\u201d&gt;<\/em><br \/>\n<em>\u00a0\u00a0 \u00a0\u00a0\u00a0 \u00a0\u00a0\u00a0 \u00a0\u00a0\u00a0 \u00a0\u00a0\u00a0 \u00a0&lt;tr&gt;<\/em><br \/>\n<em>\u00a0\u00a0 \u00a0\u00a0\u00a0 \u00a0\u00a0\u00a0 \u00a0\u00a0\u00a0 \u00a0\u00a0\u00a0 \u00a0&lt;td align=\u201ccenter&#8221;&gt;Hello&lt;\/td&gt;<\/em><br \/>\n<em>\u00a0\u00a0 \u00a0\u00a0\u00a0 \u00a0\u00a0\u00a0 \u00a0\u00a0\u00a0 \u00a0\u00a0\u00a0 \u00a0&lt;\/tr&gt;<\/em><br \/>\n<em>\u00a0\u00a0 \u00a0\u00a0\u00a0 \u00a0\u00a0\u00a0 \u00a0\u00a0\u00a0 \u00a0&lt;\/table&gt;<\/em><br \/>\n<em>\u00a0\u00a0 \u00a0\u00a0\u00a0 \u00a0\u00a0\u00a0 \u00a0&lt;\/td&gt;<\/em><br \/>\n<em>\u00a0\u00a0 \u00a0\u00a0\u00a0 \u00a0\u00a0\u00a0 \u00a0&lt;\/tr&gt;<\/em><br \/>\n<em>\u00a0\u00a0 \u00a0\u00a0\u00a0 \u00a0&lt;\/table&gt;<\/em><br \/>\n<em>\u00a0\u00a0 \u00a0&lt;\/td&gt;<\/em><br \/>\n<em>\u00a0\u00a0 \u00a0&lt;\/tr&gt;<\/em><br \/>\n<em>&lt;\/table&gt;<\/em><\/p>\n<p class=\"font_8\">\nThe first outer table is set at 100% width to ensure the table is centred within the main body of the email itself. \u00a0Then the body table is set at your desired email width (i.e. 700px as\u00a0above) with a 100% media query class. \u00a0By setting the tables within the body to 100%, this helps to ensure the content flows responsively when scaled down to a smaller screen resolution.<\/p>\n<p>&nbsp;<\/p>\n<p class=\"font_8\"><strong>Handy tip:<\/strong>\u00a0When building emails using tables, make sure you repeat\u00a0your inline styles. \u00a0A\u00a0table within a table will lose styling in some email clients, especially background colour and font attributes.<br \/>\n<strong>And another handy tip:<\/strong>\u00a0Try and make sure you nest\u00a0your tables, and avoid using colspans in your email code. Outlook has a nasty habit of ignoring colspans and rowspans, so nesting your tables will give you more control over your code, making you a happier developer.<\/p>\n<p>&nbsp;<\/p>\n<h4 class=\"font_8\">6).\u00a0A font by any other name<\/h4>\n<p class=\"font_8\">Be on the lookout in Outlook, your font might not be the font you wanted!<br \/>\nHaving a backup or fallback font within your email code is exceptionally useful to ensure your emails always look\u00a0the way you want them to, even if the email provider doesn&#8217;t have your first choice font.<\/p>\n<p class=\"font_8\">However&#8230;\u00a0Outlook 2007\/10\/13 has other ideas, and will automatically apply their own fallback font or Times New Roman. Even if you set fallback fonts in your code, Outlook ignores them. Cheers Outlook.<\/p>\n<p class=\"font_8\">\n<strong>But wait, there is a fix.. phew!<\/strong><br \/>\n<em>&lt;!&#8211;[if mso]&gt;<\/em><br \/>\n<em>&lt;style type=\u201dtext\/css\u201d&gt;<\/em><br \/>\n<em>\u00a0\u00a0 \u00a0body, table, td {font-family: Arial, sans-serif, Helvetica !important;}<\/em><br \/>\n<em>&lt;\/style&gt;<\/em><br \/>\n<em>&lt;![endif]&#8211;&gt;<\/em><\/p>\n<p class=\"font_8\">\nDrop this code into the &lt;head&gt; of an email and Outlook will pick up the web safe fonts first, so you can safely steer clear of Times New Roman.<br \/>\nFont-astic!<\/p>\n<h4 class=\"font_8\">\n7).\u00a0Does my article look big in this?<\/h4>\n<p class=\"font_8\">A bit of extra padding never did anyone any harm, but adding Padding and Margins to your table styles\u00a0could harm the way your email looks, as some email clients might ignore them.<\/p>\n<p class=\"font_8\">\nSpacer images used to be the way to use padding in emails. Developers would use transparent 12px x 12px gifs and fit them into every nook and cranny of their emails&#8230; sounds tedious doesn&#8217;t it?<\/p>\n<p class=\"font_8\">Luckily there is an alternative which is much more efficient to implement, and works across all email clients successfully&#8230;\u00a0A\u00a0non-breaking space\u00a0(&amp;nbsp;)\u00a0&#8211; just add font size, line height and a width\/height depending on the space you require:<\/p>\n<p class=\"font_8\">\n<em>&lt;td style=&#8221;font-size:20px; line-height:20px;&#8221; height=&#8221;20&#8243;&gt;&amp;nbsp;&lt;\/td&gt;<\/em><\/p>\n<p class=\"font_8\">\n<p class=\"font_8\">So now your emails and tables will always be lean and evenly spaced&#8230;no padding required.<\/p>\n<p class=\"font_8\">\n<h4 class=\"font_8\">8).\u00a0The (Alt)ernative<\/h4>\n<p class=\"font_8\">\u00a0When your emails load quickly, you get to display every image and aspect of you email in all its glory. But what happens when you\u2019re a slow connection speed or your email client is blocking images by default?<\/p>\n<div id=\"innercomp_l0d22fz6\" class=\"s_heNoSkinPhoto\" title=\"\" data-exact-height=\"115.62133333333334\" data-content-padding-horizontal=\"0\" data-content-padding-vertical=\"0\">\n<div id=\"innercomp_l0d22fz6link\" class=\"s_heNoSkinPhotolink\">\n<div id=\"innercomp_l0d22fz6img\" class=\"s_heNoSkinPhotoimg\" data-style=\"\"><img decoding=\"async\" id=\"innercomp_l0d22fz6imgimage\" class=\"alignleft\" src=\"https:\/\/static.wixstatic.com\/media\/0cf246_55b86dabe87d4bdab8cc8e03e9045535~mv2.jpg\/v1\/fill\/w_124,h_116,al_c,lg_1,q_80\/0cf246_55b86dabe87d4bdab8cc8e03e9045535~mv2.webp\" alt=\"\" data-type=\"image\" \/><\/div>\n<\/div>\n<\/div>\n<p class=\"font_8\">You could end up with empty spaces where your images used to be, but hopefully you will see the\u00a0<strong>Alt text<\/strong>\u00a0&#8211; the alternative text that&#8217;s displayed when an image can&#8217;t display.<\/p>\n<p class=\"font_8\">Some email clients won&#8217;t load images automatically, so without any Alt text you could get a blank looking email.\u00a0\ud83d\ude41<\/p>\n<p class=\"font_8\">\n<p class=\"font_8\">\n<p class=\"font_8\"><strong>Example Alt text:<\/strong><br \/>\n<em>&lt;img src=\u201cimages\/hello-world-title.jpg\u201d width=&#8221;200&#8243; height=&#8221;40&#8243;\u00a0alt=\u201cHello World&#8221;\/&gt;<\/em><\/p>\n<p class=\"font_8\">\nAnother alternative is to actually style your Alt text so that it&#8217;s less bland if it gets displayed. Add a font-family, font-size, font-colour or text-decoration, so you try and match the image style, and get your email looking good if the images don&#8217;t load.<\/p>\n<p class=\"font_8\">\n<p class=\"font_8\"><strong>Example stylised Alt text:<\/strong><br \/>\n<em>&lt;img src=\u201cimages\/hello-world-title.jpg\u201d width=&#8221;200&#8243; height=&#8221;40&#8243;\u00a0alt=\u201cHello World\u201d style=\u201cfont-size:16px; font-weight: bold; font-family: Arial, Helvetica, sans-serif; color:#ffffff;\u201d\/&gt;<\/em><\/p>\n<p class=\"font_8\">\n<h4 class=\"font_8\">9).\u00a0Hamburger to go please<\/h4>\n<p class=\"font_8\">Now that emails have further CSS3 support, it&#8217;s allowed many developers to start introducing some great responsive features to their email code.<\/p>\n<div id=\"innercomp_hytl1sk2\" class=\"s_heNoSkinPhoto\" title=\"\" data-exact-height=\"104.32000000000001\" data-content-padding-horizontal=\"0\" data-content-padding-vertical=\"0\">\n<div id=\"innercomp_hytl1sk2link\" class=\"s_heNoSkinPhotolink\">\n<div id=\"innercomp_hytl1sk2img\" class=\"s_heNoSkinPhotoimg\" data-style=\"\"><img decoding=\"async\" id=\"innercomp_hytl1sk2imgimage\" class=\"alignleft\" src=\"https:\/\/static.wixstatic.com\/media\/0cf246_e49754e85e984457b0b32380f09439c8~mv2.jpg\/v1\/fill\/w_105,h_105,al_c,lg_1,q_80\/0cf246_e49754e85e984457b0b32380f09439c8~mv2.webp\" alt=\"\" data-type=\"image\" \/><\/div>\n<\/div>\n<\/div>\n<p class=\"font_8\">The Hamburger Menu (so called because it looks like a little burger between a bun) is one example of this.<\/p>\n<p class=\"font_8\">Those long menus on an email don\u2019t need to be stacked half way down your mobile screen anymore, they can be tucked away neatly in a clickable, drop down menu, making your email more mobile-friendly and more visually appealing. \u00a0Just need the fries to go with it now!<\/p>\n<p class=\"font_8\">\n<p>&nbsp;<\/p>\n<h4 class=\"font_8\">10).\u00a0Give yourself a fighting chance<\/h4>\n<p class=\"font_8\">Make sure you are putting yourself in the best possible position for email building. One of the ways you can do this is to get the right software. Lucky for you, we\u2019ve put together a list of our favourite\u00a0email development tools, from design right through to deployment.<\/p>\n<p class=\"font_8\">Whatever you do, keep experimenting with your HTML\/CSS\u00a0emails, even if you end up with\u00a0Frankenstein&#8217;s monster\u00a0there might be a small part that works really well, or another that will give you a further understanding of where to go next.<\/p>\n<p class=\"font_8\">Happy coding!<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Say the words\u00a0\u201cBuild me an email\u201d\u00a0to a developer and watch the expression on their face drop. Yes, HTML emails are old school, but there\u2019s no need to don a loin cloth and start chipping out code from a stone tablet. Email has come on leaps and bounds within the last few years, and with open rates frequently increasing on mobile&#8230;<\/p>\n","protected":false},"author":1,"featured_media":484,"comment_status":"closed","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[32,29,33],"tags":[38,35,36,10,24,9,37],"class_list":["post-483","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-css","category-email","category-responsive","tag-advice","tag-blog","tag-code","tag-css","tag-email","tag-html","tag-tips"],"_links":{"self":[{"href":"http:\/\/pauldipper.com\/index.php?rest_route=\/wp\/v2\/posts\/483","targetHints":{"allow":["GET"]}}],"collection":[{"href":"http:\/\/pauldipper.com\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"http:\/\/pauldipper.com\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"http:\/\/pauldipper.com\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"http:\/\/pauldipper.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=483"}],"version-history":[{"count":4,"href":"http:\/\/pauldipper.com\/index.php?rest_route=\/wp\/v2\/posts\/483\/revisions"}],"predecessor-version":[{"id":505,"href":"http:\/\/pauldipper.com\/index.php?rest_route=\/wp\/v2\/posts\/483\/revisions\/505"}],"wp:featuredmedia":[{"embeddable":true,"href":"http:\/\/pauldipper.com\/index.php?rest_route=\/wp\/v2\/media\/484"}],"wp:attachment":[{"href":"http:\/\/pauldipper.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=483"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"http:\/\/pauldipper.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=483"},{"taxonomy":"post_tag","embeddable":true,"href":"http:\/\/pauldipper.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=483"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}