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

alex picture alex · Oct 11, 2010 · Viewed 78.7k times · Source

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?

Answer

mschonaker picture mschonaker · Oct 11, 2010

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.

UPDATE: after several down votes from people that gets angry when you tell them to follow standards, I'll expose some reasons of 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't never know which ones.
  3. It's easier to find (server side) components that follow format standards, and thus less error prone. Parsers not following standards could possibly break, making your email not getting shown.