Module 3: Document Structure and Metadata
The HTML Doctype and Standards Mode
Explain why modern HTML documents start with a doctype and what it tells the browser.
The first line of a modern HTML document should be:
<!doctype html>
This declaration tells the browser to render the document in standards mode. It is not an HTML element and it does not point to a separate file. The short modern form replaced older doctypes that included long DTD references.
Without a doctype, some browsers may use quirks mode. Quirks mode preserves rendering behaviors from older web pages, including differences in layout calculations. A new project has no reason to opt into those historical behaviors.
Doctype is not a version switch#
You may hear people say “HTML5 doctype.” The declaration is still used by the current HTML Living Standard. It does not freeze a page to a particular generation of HTML or prevent use of newer elements supported by browsers.
Put the doctype at the very start of the document, before the html element. If a layout behaves strangely, check the browser’s document mode in developer tools before reaching for a CSS workaround.