Proper HTML

Clean, strict markup is the best way to go.

What is “proper” HTML? Is it strictly standards-based? Or is it “de facto” based on the most popular browser? What difference does it make? Is it worth the effort? Why’s there still so much legacy markup around, and what’s wrong with it?

A few years back, I started converting all my HTML work to XHTML-1.0 Strict and running it through the validator. It kept saying things like, “There is no such tag ‘WIDTH’” and “There is no such tag ‘FONT’” and so forth. Thus, I learned what is Strict and what is Transitional, and after a while it started to make sense. Now it makes a lot of sense.

Many good HTML coders learned HTML way back in the 90’s, when tags were UPPERCASE and unclosed, and proprietary attributes were ammunition in the browser wars of the decade. But now it’s time to catch up.

The Myths

It’s amazing how myths, traditions, and ideologies proliferate, and HTML markup is no exception. Let’s dig around in a few of them, just for fun.

Well, YMMV… And it’s all what you’re used to… But if you want to go Strict, here’s a few pointers.

Going Strict

Some Examples

Let’s take some deprecated markup and fix it.

<HTML><HEAD><TITLE>Deprecated Tag Soup</TITLE></HEAD>
<BODY BGCOLOR=WHITE LINK=0000FF ALINK=FF0000 VLINK=FF00FF>
<H1>Bla bla bla.</H1>
<P>Some text.<P>Some more text.<P>Don't close me or else!
<DIV ALIGN=CENTER><CENTER>
<TABLE BGCOLOR=FFFFFF CELLSPACING=2 CELLPADDING=4 BORDERCOLOR=BLACK BORDER=1>
<TBODY>
<TR>
<TD ALIGN=LEFT VALIGN=TOP><FONT SIZE=2 FACE=ARIAL COLOR=0>Bla Bla Bla</FONT></TD>
<TD ALIGN=LEFT VALIGN=TOP><FONT SIZE=2 FACE=ARIAL COLOR=0>Bla Bla Bla</FONT></TD>
<TD ALIGN=LEFT VALIGN=TOP><FONT SIZE=2 FACE=ARIAL COLOR=0>Bla Bla Bla</FONT></TD>
</TR>
<TR>
<TD ALIGN=LEFT VALIGN=TOP><FONT SIZE=2 FACE=ARIAL COLOR=0>Bla Bla Bla</FONT></TD>
<TD ALIGN=LEFT VALIGN=TOP><FONT SIZE=2 FACE=ARIAL COLOR=0>Bla Bla Bla</FONT></TD>
<TD ALIGN=LEFT VALIGN=TOP><FONT SIZE=2 FACE=ARIAL COLOR=0>Bla Bla Bla</FONT></TD>
</TR>
<TR>
<TD ALIGN=LEFT VALIGN=TOP><FONT SIZE=2 FACE=ARIAL COLOR=0>Bla Bla Bla</FONT></TD>
<TD ALIGN=LEFT VALIGN=TOP><FONT SIZE=2 FACE=ARIAL COLOR=0>Bla Bla Bla</FONT></TD>
<TD ALIGN=LEFT VALIGN=TOP><FONT SIZE=2 FACE=ARIAL COLOR=0>Bla Bla Bla</FONT></TD>
</TR>
</TBODY>
</TABLE></CENTER></DIV>
<P><IMAGE SRC="some.gif" ALIGN=RIGHT HSPACE=10 VSPACE=10 BORDER=0 WIDTH=100 HEIGHT=100>
<UL>
<LI>Some text.<
<LI>Some text.<
<LI>Don't close me either!</UL></BODY></HTML>

Temporarily allow popups and .

UGH! Writing that gave me a headache! It’s no wonder some people hate HTML. Just imagine what that kind of mess looks like in a real web page with three columns and nested tables and images and embeds and content…

Now let’s see what strict markup looks like. First the CSS:

body { margin:20px; font:1.0em/1.5em Verdana,Geneva,"DejaVu Sans",sans-serif;
       background:url('paper.jpg') scroll repeat left top; }
a         { color:#3344CC; text-decoration:none; }
a:visited { color:#3344AA; }
a:hover   { color:#CC3333; background:#DDDDDD; }
p         { margin-top:0; margin-bottom:0.5em; line-height:1.5em; }
ul,ol     { margin-top:0; margin-bottom:0.5em; line-height:1.5em; }
li        { margin-top:0.5em; margin-bottom:0; }
h1,h2,h3,h4,h5 { margin:0 0 0.5em 0; color:#2C7590;
 font-family:'Century Gothic',futura,'URW Gothic L',sans-serif; }
table     {
 border-collapse:collapse; width:auto; margin:0.5em auto 1em auto;
 background:url('img/paper2.jpg') repeat scroll left top; }
th,td     {
 padding:0 3px 1px 3px; vertical-align:top;
 background:transparent; border:2px solid #FFFFFF;
 font-size:0.9em; text-align:left; }
th { color:#2C7590; text-align:left; } /* center is default for th */
td { color:#404040; }  /* left is default for td */
img { border:0; }
.fr { float:right; margin:0 0 10px 10px; }
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN"
 "http://www.w3.org/TR/HTML4/strict.dtd">
<html lang="en">
<head>
 <meta http-equiv="Content-Language" content="en-us">
 <meta http-equiv="Content-Type" content="text/HTML; charset=iso-8859-1">
 <meta name="description" content="Some description">
 <meta name="keywords" content="some keywords">
 <title>Strict HTML</title>
 <link rel="stylesheet" href="the-above.CSS" type="text/CSS">
</head>
<body>
 <h1>Bla bla bla.</h1>
 <p>Some text.</p>
 <p>Some more text.</p>
 <p>Close my tags!</p>
 <table>
  <tr>
   <td>Bla Bla Bla</td>
   <td>Bla Bla Bla</td>
   <td>Bla Bla Bla</td>
  </tr>
  <tr>
   <td>Bla Bla Bla</td>
   <td>Bla Bla Bla</td>
   <td>Bla Bla Bla</td>
  </tr>
  <tr>
   <td>Bla Bla Bla</td>
   <td>Bla Bla Bla</td>
   <td>Bla Bla Bla</td>
  </tr>
 </table>
 <p><img class="fr" src="some.gif" alt="Some Gif"></p>
 <ul>
  <li>Some text.</li>
  <li>Some more text.</li>
  <li>Close mine, too!</li>
 </ul>
</body>
</html>

Temporarily allow popups and .

Whew! That’s better. Okay, so I built and then destroyed a straw-man—I admit it. But let’s make a few observations.

It hardly seems worth the effort to learn and write all that CSS for one page, but what about 10 pages, or 100? The more pages one adds, the better that CSS looks! Add header, footer, and menu include files, and you end up with lean code indeed—as minimally marked as possible, with nothing repeated twice.

Please see the other articles in this series for more in-depth examples.

— KV5R is disabled. Please help. —

Valid HTML 5 Valid CSS WCAG 1 conformance Handmade with Ultra Edit Studio Xara Xtreme