Skip to content

What is the Doctype

New Course Coming Soon:

Get Really Good at Git

Any HTML document must start with a Document Type Declaration, abbreviated Doctype, which tells the browser the version of HTML used in the page

Any HTML document must start with a Document Type Declaration (abbreviated doctype) in the first line, which tells the browser the version of HTML used in the page.

This doctype declaration (case insensitive):

<!doctype html>

tells the browser this is an HTML5 document.

Browser rendering mode

With this declaration, the browser can render the document in standards mode.

Without it, browsers render the page in quirks mode.

If you’ve never heard of quirks mode, you must know that browsers introduced this rendering mode to make pages written in an “old style” compatible with new functionality and standards used. Without it, as browsers and HTML evolved, old pages would break their appearance, and the Web Platform has historically been very protective in this regard (which I think is part of its success).

Browsers basically default to quirks mode unless they recognize the page is written for standards mode.

You want standards mode, and

<!doctype html>

is the way to get it.

There’s an additional care to be put for Internet Explorer <= 10 users to avoid quirks mode, and it’s to put

<meta http-equiv="X-UA-Compatible" content="IE=Edge" />

in the page <head> tag, before loading any script.

Older HTML versions

HTML has a weird set of versions:

The doctype of an HTML 4.01 Strict document was:

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

XHTML was similar:

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

They required a DTD (Document Type Definition) because those old HTML versions were based on SGML, a format that defines the structure of a document.

XHTML also required the html tag to have a namespace, like this:

<html xmlns=""></html>

Those doctype declarations always required you to save the DTD declaration somewhere, as it’s nearly impossible to memorize. Also, there were different DTDs for strict mode or transitional mode (which was less strict).

XHTML is an XML vocabulary, while HTML4 (and lower) is an SGML application. The current HTML, HTML5, is heavily inspired by HTML4, but is not an SGML application, and abandoned many of the strict rules of XHTML.

HTML5 is not based on SGML, but on its own standard, so the DTD is not required, and we benefit from this in this very simple declaration:

<!doctype html>
Are you intimidated by Git? Can’t figure out merge vs rebase? Are you afraid of screwing up something any time you have to do something in Git? Do you rely on ChatGPT or random people’s answer on StackOverflow to fix your problems? Your coworkers are tired of explaining Git to you all the time? Git is something we all need to use, but few of us really master it. I created this course to improve your Git (and GitHub) knowledge at a radical level. A course that helps you feel less frustrated with Git. Launching May 21, 2024. Join the waiting list!
→ Read my DOM Tutorial on The Valley of Code
→ Read my Browser Events Tutorial on The Valley of Code
→ Read my Browser APIs Tutorials on The Valley of Code

Here is how can I help you: