Validation and DTDs

When typing in HTML code it is very easy to make a mistake and leave out a closing tag or a quotation mark. Sometimes a browser will overlook the error. At other times it may not. A browser that will overlook a closing tag will make the developer think that the page is coded properly. However, in many instances this is not true. Poorly coded HTML may work in today's browsers but this does not gurantee that these pages will work in future browsers. The only way to ensure that your pages will work in future browsers is to code according to standards. This is where validation comes in. Validation is the process of comparing your HTML code against the HTML standard set by the W3C.

<html>

<head>

<title>Animals<title>

</head>

<body bgcolor="gray>

<p><img src="images/dog.jpg" alt="A dog"></p>

<h1>Pit Bulls</h2>

<p>I really hate dogs. Some people like them.

<h2>Poodles

< p><ahref="http://www.poodle.com">Find a poodle</a></p>

<h3>Top Dog Breeds:</h3>

<ul>
<li>Bulldog
<li>Labrador Retriever </li>
<li>Shih Tzu </li>
<li>Dachshund </li>
</ul>

</body>

</html>

Errors:

  • Missing slash in closing tag of title element
  • Missing quotation mark in bgcolor attribute of the opening body tag
  • No slash before close of img element in the first paragraph
  • Wrong closing tag for h1 element around "Pit Bulls"
  • No closing tag for the second p element
  • No closing tag for the h2 element
  • Space between opening bracket and the word p in the third p element
  • Missing space between a and href for link around "Find a poodle"
  • No closing tag for the first list item in the ul element

No matter how long you look at the code, you may still miss a few errors. Color coding helps with some issues but not all. There are online tools that will automatically validate your HTML code. The W3C and the Web Design Group (WDG) offer online validation on their sites. Some HTML editors, such as Dreamweaver, have validators built into them. We're going to look at the definitive validator, that's brought to you by the people responsible for HTML, the W3C.

Document Type Definition

HTML 4.01 or XHTML 1.0 consists of 3 versions:

  • strict
  • transitional
  • frameset

These are each referred to as a Document Type Definition, or DTD. For example, the "DTD XHTML 1.0 Transitional", and so on. A browser looks for a DTD at the top of the page. This lets the browser know whether or not the page coded according to standards. A browser will display a page differently based on a DTD. There are two modes that a browser will display a page in. They are standard and quirks. A DTD will result in the browser running in standards mode. In this mode the browser expects the pages to be coded according to standards and therefore will not be forgiving when it comes to errors in HTML code and the usage of deprecated tags and attributes. In quirks mode the browser will allow deprecated tags and attributes. More info on quirks mode.

The DTD also tells validators which specifications to compare your code against. These three DTDs mean the same thing whether you are referring to HTML or XHTML, as follows.

Strict

This is the recommended version to use for maximum forward compatibility. It is "strict" because the usage of deprecated elements and attributes are not allowed. Deprecated elements and attributes are those which will be removed from future versions of HTML and XHTML. In most cases they deal with the presentation and are replaced with style sheets.

shows deprecated tags

Document Type Declaration:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">

Transitional

This version is known as the "loose" version. It allows the use of all of the deprecated attributes and elements. This enables the validation of pages which use them.

Document Type Declaration:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

Frameset

The Frameset version is the same as the transitional version, but it also allows the use of frames.

Document Type Declaration:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Frameset//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-frameset.dtd">

It is important to create documents that can be correctly validated against one of these document types. This validation process ensures that the document conforms to the grammar (document type) for the version of HTML or XHTML we have chosen.