Uppercase or lowercase doctype?

joshnh picture joshnh · Aug 11, 2011 · Viewed 47.9k times · Source

When writing the HTML5 doctype what is the correct method?

<!DOCTYPE html>

or

<!doctype html>

Answer

Mathias Bynens picture Mathias Bynens · Feb 2, 2012

In HTML, the DOCTYPE is case insensitive. The following DOCTYPEs are all valid:

<!doctype html>
<!DOCTYPE html>
<!DOCTYPE HTML>
<!DoCtYpE hTmL>

In XML serializations (i.e. XHTML) the DOCTYPE is not required, but if you use it, DOCTYPE should be uppercase:

<!DOCTYPE html>

See The XML serialization of HTML5, aka ‘XHTML5’:

Note that if you don’t uppercase DOCTYPE in an XHTML document, the XML parser will return a syntax error.

The second part can be written in lowercase (html), uppercase (HTML) or even mixed case (hTmL) — it will still work. However, to conform to the Polyglot Markup Guidelines for HTML-Compatible XHTML Documents, it should be written in lowercase.