The HTML doctype is a single declaration, <!DOCTYPE html>, that must appear as the very first line of an HTML document, before the <html> tag. It tells the browser to render the page in standards mode using HTML5 rules. Without it, browsers fall back to quirks mode and emulate 1990s Internet Explorer behavior.
Different doctype declarations trigger different rendering modes. The table below shows the common ones and what they do.
| Declaration | Mode Triggered | Standard / Year |
|---|---|---|
| <!DOCTYPE html> | Standards (full) | HTML5 (2014) |
| <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd"> | Standards | HTML 4.01 Strict (1999) |
| <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" ...> | Standards | XHTML 1.0 Strict (2000) |
| <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" ...> | Almost-standards | XHTML 1.0 Transitional |
| (no doctype, malformed, or HTML 2.0) | Quirks | Pre-1999 IE behavior |
Browsers pick a rendering mode based on the doctype. There are exactly three:
Use this exact declaration as the first line of every HTML document.
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Page Title</title>
</head>
<body>
<!-- Page content -->
</body>
</html>The doctype is case-insensitive. <!doctype html>, <!DOCTYPE HTML>, and <!DOCTYPE html> all work the same way.
Open the browser console on any page and run:
document.compatMode
// "CSS1Compat" -> standards mode (correct)
// "BackCompat" -> quirks mode (broken)No. It is a document type declaration that precedes the HTML. It does not have a closing tag and does not nest inside any element.
No. HTML5 dropped the DTD requirement. <!DOCTYPE html> is complete on its own.
Not directly. But quirks mode can break layout and Core Web Vitals, which do affect rankings. Automated Best Practices audits flag missing doctypes.
CSS widths include padding and border, table cells align differently, getElementById may behave case-insensitively, and several modern APIs may misbehave. Cross-browser rendering becomes unpredictable.
No. The HTML5 spec defines it as case-insensitive. Convention is uppercase DOCTYPE for readability.
Yes. The HTML5 doctype is backward compatible. Existing markup keeps working, and the page renders in standards mode.
Yes. Next.js renders <!DOCTYPE html> automatically for every page. You only need to worry about the doctype in static HTML files or hand-built templates.
Email clients vary. Many strip it. For email, focus on inline styles and table-based layouts rather than relying on standards mode.
Indirectly, yes. AI search engines (ChatGPT, Perplexity, Google AI Overviews) preferentially cite well-ranked, well-structured pages, and pages rendered in quirks mode often produce inconsistent layouts and broken DOM structures that machine parsers stumble on. Malformed or missing doctypes raise the chance that AI extractors misread your content or skip it for a cleaner-looking competitor.
Add <!DOCTYPE html> as the first line of every HTML document. It costs nothing, takes one line, and is the difference between standards mode and quirks mode. Verify with document.compatMode in the console and run an automated audit to confirm the "Page has the HTML doctype" check passes. Run a Greadme deep scan to verify the doctype across every page on your site so a single missing template line never quietly breaks a section of your site.