< Back

Understanding Doctypes in HTML



Back in the 1990s, when I first started developing websites, there was very little in the way of 'web standards'. There were two main web browsers, Netscape Navigator and Internet Explorer, and people wrote HTML so that their web pages looked correct in those two browsers.

In the beginning, HTML documents were simply started with an <HTML> tag:

		<P>A simple web page.

When web standards started being written, it became necessary to be able to determine what standard a particular HTML document was following. Because of this, DOCTYPEs were added.

DOCTYPEs Are Not Just For HTML

A Document Type Declaration (DOCTYPE) is a special statement at the beginning of a document that states what sort of document it is. DOCTYPEs are not unique to HTML files, but can also be found in SGML and XML files.

Modern web browsers will often display a web page differently, depending on the DOCTYPE of the page, so it is very important that you consistently use the correct DOCTYPE when creating web pages.

There are three DOCTYPEs for HTML pages that are commonly used today.

HTML 4.01

The following shows the DOCTYPE for HTML 4.01 documents. This has been the dominant DOCTYPE on the web for many years, but is soon to be overtaken by HTML5:

	"-//W3C//DTD HTML 4.01//EN"

		<p>An HTML 4.01 web page.</p>


Similar to HTML 4.01, the XHTML 1.0 standard is a little more strict in its syntax:

	"-//W3C//DTD XHTML 1.0 Strict//EN"

<html xmlns="http://www.w3.org/1999/xhtml">
		<p>An XHTML 1.0 web page.</p>

Technically, XHTML 1.0 documents are also XML files, so they are also supposed to have an XML declaration before the DOCTYPE, but in practice this is omitted due to some versions of Internet Explorer rendering pages incorrectly.


HTML5 is the latest and greatest HTML standard. Many of its features are still being developed, but it is likely to quickly become the dominant DOCTYPE on the web.

<!DOCTYPE html>

		<p>An HTML5 web page.</p>