When creating HTML emails, should we use html, head, body tags?

HtmlEmailHtml Email

Html Problem Overview


In my email views, I usually just do something like...

<dl>
   <dt>Name</dt>
   <dd>Value</dd>
</dl>

Should I be doing it like this?

<html>
  <head></head>
  <body>
    <dl>
       <dt>Name</dt>
       <dd>Value</dd>
    </dl>
  </body>
</html>

In other words, like I was marking up a standalone document?

I guess I can safely assume any web based email client will strip it out?

What is the right way?

Html Solutions


Solution 1 - Html

The right way is to follow the HTML standard. You can validate your HTML page here.

Your mail client should follow it and should throw away what's not supported or what's insecure, like JavaScript.

I'll expose some reasons why following standards could be beneficial here:

  1. a webmail willing to show your mail as a full page, could keep your format.
  2. a webmail will simply strip the tags and attributes it doesn't want. But you can never know which ones.
  3. It's easier to find (server side) components that follow format standards, and thus are less error prone. Parsers not following standards could possibly break, making your email not getting shown.

Solution 2 - Html

Whether or not you include the html/head/body tags is entirely irrelevant — they are always optional and will not affect the rendering of the document in any way.

What matters most is whether quirks mode is on or not. Unfortunately, you can’t control that in a webmail setting. Tables and inline styles are your friends. Your best bet is to test in as many webmail and desktop clients as you can.

Solution 3 - Html

Many of the posts on this thread are rather old, and as a result they are no longer accurate.

These days HTML emails should include a doctype, html and body declaration if you intend to do anything fancy at all.

There are a multitude of guides on this subject which can help you learn how to properly code HTML Email, but most of them disregard the specifics of a doctype, which is how I stumbled on your question.

I suggest you read the following 2 posts which are from reputable teams familiar with the various problems:

campaign monitor's take

email on acid's take

Solution 4 - Html

Depends entirely on the email client that receives it. In my experience, most email clients that will interpret HTML don't care if you have full body/head/html tags, etc. In fact you don't even need those tags for most browsers. You need to have the head tags to include style/title, etc. Otherwise they are not really necessary, per se. I've never seen them to be necessary.

Solution 5 - Html

There's 1 thing I know to be true: Using HTML opening and closing tags will help in general spam scoring due to the fact that many such appliance based filters and software firewalls will add a point or so to an email that uses html but does not use the opening and closing tags.

Solution 6 - Html

I don't think there is a right way but trying to make the email viewable in as many email readers as posible.

I usually check the emails in Thunderbird, because Outlook forgives more.

In Thunderbird this is the HTML code for an email (i have an extension that shows the html)

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<meta http-equiv="content-type" content="text/html; charset=ISO-8859-1">
</head>
<body bgcolor="#ffffff" text="#000000">
        This is the body text<br>
<div class="moz-signature"><i><br>
<br>
Regards<br>
Alex<br>
</i></div>
</body>
</html>

BTW, i use plain text email for all my web forms every time I can. I had many issues with blackberry email using html+plain text emails.

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
QuestionalexView Question on Stackoverflow
Solution 1 - HtmlMartín SchonakerView Answer on Stackoverflow
Solution 2 - HtmlJosh LeeView Answer on Stackoverflow
Solution 3 - HtmlkamelkevView Answer on Stackoverflow
Solution 4 - HtmlExplosion PillsView Answer on Stackoverflow
Solution 5 - HtmlGregView Answer on Stackoverflow
Solution 6 - HtmlAlex AngelicoView Answer on Stackoverflow