Skip to content
AITroveRead. Build. Understand.
Make this comfortable

HTML doctype: keep the browser in standards mode

Last updated: 1 Oct 20267 min read
tutorial
IntermediateBy AITrove Editorial

The HTML doctype selects standards mode before the browser lays out the rest of a document.

When the element earns its place

A claims portal renders a printable decision and a screen version from the same template. Put the doctype first so layout rules do not depend on legacy quirks behavior. The declaration is short because HTML does not use it to select a schema or a particular browser version. The rest of the head still needs an encoding declaration, a title that identifies this decision, and a language on the root element.

html
<!doctype html>
<html lang="en">
<head>
  <meta charset="utf-8">
  <title>Claim C-47 decision</title>
</head>
<body>
  <main><h1>Claim C-47 decision</h1><p>Review pending.</p></main>
</body>
</html>

Behavior boundary

Standards mode concerns rendering and layout. It does not prove that the document is well formed, accessible, or connected to a valid claim; those are separate checks. Inspect document.compatMode when investigating a legacy template with unexplained sizing.

Cost and operational limits

The doctype transfers only a few bytes. Omitting it may trigger compatibility rules whose debugging cost far exceeds the bytes saved, particularly when older stylesheets rely on box measurements.

Common Mistakes

  • Do not move the doctype below comments or visible content.
  • Do not treat the doctype as a substitute for HTML validation.
  • Do not assume a valid title or language follows from standards mode.

Connected lessons

html
core
Storage details