The doctype is the very first thing in an HTML document. The HTML5 form is <!DOCTYPE html> -- short, case-insensitive, no DTD reference. Its job today is mostly historical: telling the browser whether to use modern (standards) or legacy (quirks) rendering rules.
What happens with each doctype:
<!DOCTYPE html>-- HTML5 standards mode. Modern CSS box model, modern parsing, what every dev expects.- HTML4 / XHTML doctypes (
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" ...>) -- "almost-standards" mode. Mostly behaves like standards mode, but with subtle differences (inline-block baseline, table cell sizing). - No doctype at all -- quirks mode. Browser uses 1990s-era rendering bugs to stay backward-compatible with sites built before standards existed. CSS box model is wrong, layout primitives behave oddly, JavaScript APIs may differ.
Why it still matters in 2026: quirks mode bugs surface in subtle ways. The most common: width includes padding and border in quirks mode (the old IE 5 box model) but doesn't in standards mode. A site built without a doctype will look slightly wrong on every browser made in the last 15 years -- and the developer typically doesn't realize because they tested on whichever quirks-mode browser they used during development.
Adding <!DOCTYPE html> is a one-line, no-risk fix for any page that doesn't have it.