Uppercase or lowercase doctype?

HtmlDoctype

Html Problem Overview


When writing the HTML5 doctype what is the correct method?

<!DOCTYPE html>

or

<!doctype html>

Html Solutions


Solution 1 - Html

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.

Solution 2 - Html

If anyone is still wondering in 2014, please consult this:

HTML5

[W3 HTML5 Spec - Doctype][1]

> A DOCTYPE must consist of the following components, in this order: > > 1. A string that is an ASCII case-insensitive match for the string " > ...

Note: Despite being displayed in all caps, the spec states it is insensitive.


XHTML5

[W3 HTML5 - XHTML][2]

> This specification does not define any syntax-level requirements beyond those defined for XML proper. >
> XML documents may contain a DOCTYPE if desired, but this is not required to conform to this specification. This specification does not define a public or system identifier, nor provide a formal DTD.

Looking at the XML spec, it lists DOCTYPE in caps, but I can't find anything that states that 'all caps' is required (for comparison, in the HTML5 spec listed above, it is displayed in the example in all caps, but the spec explicitly states that is is case-insensitive).


Polyglot Markup

[W3 Polyglot Markup - Intro][3]

> It is sometimes valuable to be able to serve HTML5 documents that are also well formed XML documents.

[W3 Polyglot Markup - Doctype][4]

> Polyglot markup uses a document type declaration (DOCTYPE) specified by section 8.1.1 of [HTML5]. In addition, the DOCTYPE conforms to the following rules: > > * The string DOCTYPE is in uppercase letters.
> ...

So, note that Polyglot Markup uses a regular HTML5 doctype, but with additions/changes. For our discussion, most notably that DOCTYPE is declared in all caps.


Summary

[View the W3's HTML vs. XHTML section.][5]

[Opinion] I wouldn't worry too much about satisfying XML compliance unless you are specifically trying to make considerations for it. For most client and JS-based server development, JSON has replaced XML.

Therefore, I can only see this really applying if you are trying to update an existing, XHTML/XML-based legacy system to co-exist with new, HTML5 functionality. If this is the case then look into the polyglot markup spec.

[1]: http://www.w3.org/TR/html5/syntax.html#the-doctype "W3 HTML5 Spec - Doctype" [2]: http://www.w3.org/TR/html5/the-xhtml-syntax.html#the-xhtml-syntax "W3 HTML5 - XHTML" [3]: http://dev.w3.org/html5/html-polyglot/html-polyglot.html#h2_introduction "W3 Polyglot Markup - Intro" [4]: http://dev.w3.org/html5/html-polyglot/html-polyglot.html#h3_doctype "W3 Polyglot Markup - Doctype" [5]: http://www.w3.org/TR/html5/introduction.html#html-vs-xhtml "View the W3's HTML vs. XHTML section"

Solution 3 - Html

According to the latest spec, you should use something that is a case-insensitive match for <!DOCTYPE html>. So while browsers are required to support whatever case you prefer, it's reasonable to infer from this that <!DOCTYPE html> is the canonical case.

Solution 4 - Html

Either upper or lower case is "correct". However if you use web fonts and care about IE7, I'd recommend using <!DOCTYPE html> because of a bug in IE7 where web fonts sometimes fail if using <!doctype html> (e.g. in this answer).

This is why I always upper-case the doctype.

Solution 5 - Html

The standard for HTML5 is that tags are case insensitive.

http://www.w3schools.com/html5/tag_doctype.asp

More Technically: (http://www.w3.org/TR/html5/syntax.html)

A DOCTYPE must consist of the following components, in this order:

  1. A string that is an ASCII case-insensitive match for the string <!DOCTYPE.

Solution 6 - Html

The question sort of implies there's only one correct answer, supplies a multiple choice of two, and asks us to pick one. I would suggest that for HTML5 both <!DOCTYPE html> and <!doctype html> are valid.

So a HTML5-capable browser would accept the lowercase one and process the html properly.

Browsers previous and oblivious to HTML5, I've heard, even without a doctype, will attempt to process the html as best they can. And if they don't recognize the lowercase doctype will do the same. So there's no point in making it uppercase since those browsers won't be able to fully implement any HTML5 declarations anyway.

Solution 7 - Html

The doctype declaration is case insensitive, and any string of ASCII that matches

Html5 standard

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
QuestionjoshnhView Question on Stackoverflow
Solution 1 - HtmlMathias BynensView Answer on Stackoverflow
Solution 2 - HtmlucsargeView Answer on Stackoverflow
Solution 3 - HtmlJohn MellorView Answer on Stackoverflow
Solution 4 - HtmljpwView Answer on Stackoverflow
Solution 5 - HtmlStephenView Answer on Stackoverflow
Solution 6 - HtmlCliveView Answer on Stackoverflow
Solution 7 - HtmlIchoku ChinonsoView Answer on Stackoverflow