Require A Doctype Declaration
ID |
html.doctype_declaration |
Severity |
low |
Remediation Complexity |
low |
Remediation Risk |
low |
Remediation Effort |
low |
Resource |
Reliability |
Language |
Html |
Tags |
reliability |
Rationale
The doctype is the first thing a browser reads. Without it the browser drops into quirks mode, where legacy box-model and layout bugs are emulated for backwards compatibility, so a page that renders correctly in standards mode can shift or break. A missing doctype therefore makes layout non-deterministic across browsers.
<html lang="en"> <!-- FLAW — document has no doctype declaration -->
<head><title>Hi</title></head>
<body></body>
</html>
<!DOCTYPE html> <!-- OK — doctype declared -->
<html lang="en">
<head><title>Hi</title></head>
<body></body>
</html>
Remediation
Begin the document with a doctype declaration; the modern <!DOCTYPE html> selects standards mode in
every browser.