Explain Codes LogoExplain Codes Logo

Uppercase or lowercase doctype?

html
doctype
xhtml
polyglot-markup
Nikita BarsukovbyNikita Barsukov·Jan 11, 2025
TLDR

Adhere to the HTML5 standard, always use uppercase <!DOCTYPE html>. While browsers recognize both capitalizations, convention and consistency lean towards uppercase:

<!DOCTYPE html> <!-- Hello there, standard convention! -->

It's meaningful to understand the DOCTYPE declaration because it's how we tell the browser the type of HTML we're using in our document. The HTML5 specification is ASCII case-insensitive, resulting in both uppercase and lowercase being valid.

Case considerations for DOCTYPE syntax

XHTML and XML serialization

In the context of XHTML, it's crucial to use an uppercase DOCTYPE. That's because XML parsers are case-sensitive and won't like it any other way:

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

Forget to use uppercase in XHTML, and you'll have a syntax error to fix. The XML document balks at the error and balks at being parsed.

Uniformity with Polyglot Markup and legacy systems

If you're working with Polyglot Markup, where your document has to play nice with both HTML and XHTML, the recommendation goes with lowercase. However, IE7 and some legacy systems might give you a headache with web font issues on lowercase usage - here uppercase scores extra compatibility points.

Internationalization and Accessibility: Stick to the standard

Rolling out internationalization and accessibility support? Stick to the rules. Screen readers and translation systems may have been optimized for the usual uppercase declaration.

Fine-tuning the DOCTYPE

Aligning with W3C specification

The W3C specification provides clarity stating the doctype string must match "<!DOCTYPE" based on a ASCII case-insensitive comparison, allowing flexibility in case usage, but adhering to the convention increases readability and maintainability.

Working with earlier versions and transitional DOCTYPEs

Working on older HTML versions, or touching upon transitional doctypes, may need legacy doctype declarations, which more often than not, used uppercase, staying true to the practices of old.

Doctype validation tools: Your silent critics

W3C validator and other similar tools bank on doctype for deciding the HTML version or ruleset they apply while scanning your markup. Going unconventional with the case might get you an unexpected validation result.

Best Practices: Stick with the community

The developer community conventions, in general, favor the uppercase <!DOCTYPE html>, cementing it as an unwritten standard encouraging uniformity across different codebases.