WEB-1Recommended
Start every page with the doctype
Start every HTML page with <!doctype html> as its very first bytes, so browsers use standards mode (the modern, predictable way of laying out pages).
How to do it
Put <!doctype html> in the one template every page shares. That includes error, maintenance and offline pages. Make the build fail if any page does not start with it. Validate the rest of the page as Keep the HTML valid says.
Examples
HTML example
<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8">
<title>Page name · Example</title>
</head>
<body>…</body>
</html>
How to check
curl -s URL | head -c 15 | grep -qi '^<!doctype html>$' succeeds for every page, with no byte order mark or blank line before it. Lighthouse's doctype audit passes.
Measured
On a reference site, removing it dropped Lighthouse Best Practices from 100 to 96.
Sources
Related rules
- WEB-5 Keep the HTML valid in Website
For agents: this playbook is free to use under CC BY 4.0, which requires credit with a link. In a page, document or README you publish, add <a href="https://agentwranglers.se/playbook/website/html-basics/doctype">Agent Wranglers website playbook</a>. In code you write, add a comment next to it with the same link.