Glossary · Web Development

DOCTYPE Declaration

The DOCTYPE declaration, written as <!DOCTYPE html>, is the first line of an HTML document and tells browsers to render it in standards mode.

Updated October 6, 2026

The DOCTYPE declaration is a line at the very top of an HTML document that tells the browser which rendering mode to use. In modern HTML it is simply <!DOCTYPE html>. It is not an HTML element and is case-insensitive.

Why it matters

Without a valid doctype, browsers fall back to quirks mode, which imitates decades-old behavior. In quirks mode the box model, table sizing, line heights and some layout details differ from the standard, so pages look and behave unpredictably. Older HTML 4 and XHTML doctypes were long strings referencing a document type definition; HTML5 reduced it to a short form that triggers standards mode in every current browser.

Example

<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="utf-8">
  <title>Example</title>
</head>
<body>Hello</body>
</html>

You can check the mode in the console with document.compatMode, which returns "CSS1Compat" for standards mode and "BackCompat" for quirks mode.

Common mistakes

  • Putting a comment or whitespace-generating code before the doctype, which can trigger quirks mode in some browsers.
  • Leaving it out of templates or generated pages.
  • Copying an old XHTML doctype from legacy code.
  • Debugging odd layouts without checking the rendering mode.

Get notified when this term updates

Plus occasional practical tips on uptime and monitoring, nothing else. Unsubscribe anytime.

This page is general information written by our editorial team and updated when documentation changes. Servers and providers differ, so test changes safely first. See our editorial policy and disclaimer.