HTML Quick and Dirty

The Only Two Things You Need in an HTML Document (Besides Content...)

In HTML4 and HTML5 there are only two things you need in an HTML document for it to be valid:

  • doctype
  • title element

This means that this is a valid HTML4 document:

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<title>HTML4 Minimal Markup Example</title>
This page should validate as HTML 4.01. It uses only two tags: &lt;title&gt; and the doctype.

Don't believe me? Validate it yourself, here is the page. (Note: I realize I haven't defined character encoding, which is resulting in a “tentative” valid listing. I don't have access to the About.com servers to set the character encoding. But if I did, that page would get a valid designation just as it is.)

Here is the same page written in HTML5:

<!doctype html>
<title>HTML5 Minimal Markup Example</title>
Will this page display? It should. It's written with the HTML5 doctype.

Check the page yourself.

While These Tags are the Minimum, There Are a Few More You Should Include As Well

Title and doctype are the minimum you need to write a valid web page, but you should get into the habit of using three other tags as well:

  • html
  • head
  • body

These tags provide the structure for your document, give the browsers something familiar to use and if you ever switch your documents over to XHTML, they are required in that version of the language.

If you were to re-write the above two HTML documents with these three tags they would look like this, in HTML4:

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<title>HTML4 Minimal Markup Example</title>
</head>
<body>
This page should validate as HTML 4.01. It uses only two tags: &lt;title&gt; and the doctype. </body>
</html>

And in HTML5:

<!doctype html>
<html>
<head>
<title>HTML4 Minimal Markup Example</title>
</head>
<body>
This page should validate as HTML 4.01. It uses only two tags: &lt;title&gt; and the doctype. </body>
</html>

Note: the closing tags on html, head, and body are not required, but it's a good idea to include them, so that you can add style sheets and scripts more effectively.