In this article, I am writing by summary from the article that posted on this URL http://www.sitepoint.com/code-html-email-newsletters/
There are important to note is that Mail Template is not going to show on web browser, but Email Client. Mail clients are light years behind the eight-ball in terms of CSS support, which means that we must resort to using tables for layout if we really want our newsletters to display consistently for every reader
Whether you choose to code your HTML email by hand (my personal preference) or to use an existing template, there are two fundamental concepts to keep in mind when creating HTML email:
There are important to note is that Mail Template is not going to show on web browser, but Email Client. Mail clients are light years behind the eight-ball in terms of CSS support, which means that we must resort to using tables for layout if we really want our newsletters to display consistently for every reader
Whether you choose to code your HTML email by hand (my personal preference) or to use an existing template, there are two fundamental concepts to keep in mind when creating HTML email:
- Use HTML tables to control the design layout and some presentation. You may be used to using pure CSS layouts for your web pages, but that approach just won’t hold up in an email environment.
- Use inline CSS to control other presentation elements within your email, such as background colors and fonts.
1: Use HTML Tables for Layout
Recommended to use one column or two column layout.
- For a two-column layout, create one table each for the header,
the two center content columns, and the footer — that’s three tables in
all. Wrap these tables into another container table. Use the same
approach for single-column layouts, but give the content table one
column. This approach is especially suitable if the design of your email
contains images that are broken up over multiple table cells.
Otherwise, a single table with
td
rows for its header (withcolspan="2"
if the design uses two columns), content, and footer should display fine in all but Lotus Notes email software. - Use the attributes within the table and
td
tags to control the table’s display. For example, settingborder="0"
,valign="top"
,align="left"
(orcenter
, if that suits the design),cellpadding="0"
,cellspacing="0"
, and so on. This primarily helps older email clients to display the email in a (barely) acceptable way. - Even
if the design of your email doesn’t include a border around your table,
you might find it helpful during development to set
border="1"
to help with the debugging of any problems that arise with the internal alignment oftr
andtd
tags. Change it back toborder="0"
for testing and production.
2: Use Inline CSS
- CSS style declarations appear below the
body
tag, not between thehead
tags. - No CSS shorthand is used: instead of using the abbreviated style rule
font: 12px/16px Arial, Helvetica
, you should instead break this shorthand into its individual properties:font-family
,font-size
, andline-height
. span
s anddiv
s are used sparingly to achieve specific effects, while HTML tables do the bulk of the layout work.- CSS style declarations are very basic, and do not make use of any CSS.
Important Note:
- Sometimes, a switch from percentage widths to fixed widths is needed. While this is not ideal — because readers can and do resize their email windows while reading — sometimes, using a fixed width is the only way to have a layout to display properly in multiple email clients.
- If there’s a spacing issue with the columns in the email design, first tweak the
cellpadding
andcellspacing
attributes of the HTML tables. If that doesn’t work, apply CSSmargin
andpadding
attributes. HTML spacing works better with older email software. - Image displacement can occur when a
td
cell is closed right below animg
tag. This is an ancient HTML problem. Putting thetag right after (on the same line as) the
img
tag eliminates the annoying and mystifying 1-pixel gap.
- Avoid using JavaScript. Most email software will disable it anyway.
- If an image is sliced up and spread across several HTML table cells, test the email using many test accounts. Sometimes, it might look great in Outlook but be shifted by one or more pixels in Hotmail and other services. Also consider making the image a background image on a new HTML table that encases all of the table rows and columns that would display parts of your background image; this often achieves the same effect as slicing an image up, but uses less code and can provide better results (see below). Note that Outlook 2007 does not display background images; be sure to test your email code with your target email software.
- For background images, use the table’s
background
attribute instead of using CSS. This works more consistently across email software than other potential solutions. - Store
the email images on a web server — preferably in a folder that’s
separate from your web site’s images (for example, in a folder called
/images/email
), and don’t delete them. Some people open emails weeks or months later, the same way people use bookmarks to return to web sites. - Be sure all your images use the
alt
,height
, andwidth
attributes. Setting values for these attributes improves results in Google Mail, as well as maintaining your layout when a reader has their images turned off. Note, however, that Outlook 2007 does not recognize thealt
attribute. - Use the
target="_blank"
attribute for the a tags, so that people who read with webmail services don’t have the requested page appear within their webmail interface. - While a 1×1-pixel image can be used to force spacing to create a precise email layout, spammers often use 1×1-pixel images to determine if their email has been opened. As such, using this practice will increase the likelihood that your email is classified as spam.
- Similarly, avoid using a large image "above the fold" in the email. This is another classic spammer practice and may cause your email to be interpreted as spam.
- Define the background color in a
td
cell with thebgcolor
attribute, not the CSS style. - As noted above, use the
background
attribute in thetd
cell for background images instead of using CSS. One side-effect of this approach is that the background image can be made as tall as needed — if the content used in your email template is likely to vary in size, using an extra-tall background image in this way allows the height of the email shrink or expand, depending on the height of the copy, from one email to the next. Remember, though, that Outlook 2007 ignores background images completely. - If it works better, use the padding declaration to control margins within a td cell. The margin style does not work in these cells, but padding does.
- If you need a border around a
td
cell, keep in mind that Google Mail displays a border around atd
cell when it’s defined in adiv
, but not when it’s defined as a border style in atd
tag. - If you need a light-colored link against a dark background color, put the font definition in the
td
cell (so it applies top
anda
tags equally) then add acolor:
style to the a tag. - If the
p
anda
fonts appear to be different sizes, wrap thea
tag in ap
tag. - Google Mail aggressively uses the right-hand column of the Google Mail user interface, which squeezes the HTML email into the center panel. Be sure the padding style in the content tds is set to 10 pixels all round, so that text does not hit against the left and right edges.
- When
testing an HTML email with a Google Mail account, it’s likely that
you’ll find that one or more font styles are missing in the
td
,h1
,h2
,p
,a
, and other tags. Inspect every font carefully to make sure Google Mail displays the fonts correctly.