HTML Doctypes & Validation

The HTML doctype declaration is not a tag; it is more like an instruction that tells the web browser what version of HTML is used on the page. Some browsers require a doctype declaration in order to render the webpage correctly, so it is good practice to include one.

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

<!DOCTYPE html>

The doctype declaration that is used will depend on the version of HTML that you are using. Each declaration refers to a Document Type Definition, or DTD.

<!DOCTYPE html> <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01//EN" "">

<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "">

<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Frameset//EN" "">

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "">

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "">

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Frameset//EN" "">

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN" "">

I can already hear you asking "But which doctype should I use?!". Good questions. I suggest "<!DOCTYPE html>" for HTML5, as any new pages from here on out should make use of the latest version of HTML!

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.