Detailed answer
The short HTML doctype selects standards mode in modern browsers.
Put it before the document element. It is a declaration rather than an element and does not need a closing tag. For a page with unexpected legacy layout behavior, inspect document.compatMode in the console.
Example
<!doctype html>
<html lang="en"><head><title>Standards mode</title></head><body><p>Hello</p></body></html>
Understanding the behavior
Standards mode makes browser layout follow modern rules rather than compatibility behavior for older pages. A doctype is not a link to a validator or a stylesheet, and the short HTML declaration does not require an HTML version number.
Practical implementation notes
Compare document.compatMode before and after fixing a missing doctype. If the page still looks wrong in standards mode, inspect the CSS box model rather than repeatedly changing the declaration.
How to check it
Evaluate document.compatMode in the browser console after adding the doctype at the beginning.
Expected result
A standards-mode document reports CSS1Compat.
Watch out: A reusable component should not introduce a second doctype.
Read the reference ↗