Login | Contact Us | Site Map | Resources

Introduction to HTML

Home > HTML Tutorial > HTML Doctypes & Validation

HTML Doctypes & Validation

The HTML doctype declaration is not a tag; it is more like an instruction to the web browser about what version of HTML the page is written in. Some browsers require a doctype declaration in order to render the webpage correctly.

The doctype declaration is placed at the very beginning of an HTML document, even before the opening <html> tag.

<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
  <title></title>
</head>
<body>
</body>
</html>

There are several different doctype declarations that can be used, depending on the version of the rules that your webpage follows. Each declaration refers to a Document Type Definition, or DTD.

<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">

<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">

<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Frameset//EN" "http://www.w3.org/TR/html4/frameset.dtd">

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

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

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

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN" "http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">

I can already hear you asking "But which doctype should I use?!". Good questions. I usually use 4.01 Transitional because it is the most lenient, however you can research each type to find the one most suited to your requirements on the official doctype website.

Once you have chosen your doctype you can validate your webpage to have all of the HTML errors pointed out to you, usually followed by a self-inflicted smack to the forehead, which can be accompanied by a roll of the eyes and a muttered "How could I have missed that?", all of which are, of course, optional.