The doctype is the very first line of an HTML document — it tells the browser which rendering mode to use.
Modern HTML5 Doctype
<!DOCTYPE html>
That's it — HTML5 simplified the doctype down to this single, short line. No version numbers, no URLs to a specification.
What Older Doctypes Looked Like
<!-- HTML 4.01 Strict — verbose, versioned, effectively obsolete now -->
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN"
"http://www.w3.org/TR/html4/strict.dtd">
You'll still see this in very old codebases. There's no reason to write it in a new project — always use the simple <!DOCTYPE html>.
Why It Matters: Quirks Mode vs Standards Mode
Without a doctype (or with an old/incorrect one), some browsers fall back to quirks mode — an intentionally imprecise rendering mode kept for backward compatibility with very old websites, where CSS box-model calculations and other behaviors differ from the modern standard. A correct <!DOCTYPE html> guarantees standards mode, which is what every modern CSS layout technique assumes.
Common Mistakes
- Omitting the doctype entirely — triggers quirks mode, which can cause subtle, hard-to-diagnose CSS layout bugs
- Adding anything before
<!DOCTYPE html>in the file (even whitespace/comments in some contexts) — it must be the very first thing - Writing it in lowercase like
<!doctype html>— technically works (doctype matching is case-insensitive), but uppercase is the near-universal convention
Interview Relevance
Q: "What does the doctype do, and what happens without one?" — a genuinely common fundamentals question; the quirks-mode-vs-standards-mode explanation above is exactly the expected depth of answer.
Practice Question
Explain, in one sentence, what would likely go wrong visually if a page's doctype were accidentally deleted.