The DOCTYPE declaration is the first line of every HTML document. It tells the browser which rendering mode to use. A missing or malformed DOCTYPE throws the browser into "quirks mode" — a backwards-compatibility mode that emulates 1999-era browser bugs. Quirks-mode pages render unpredictably, break responsive layout, and harm Core Web Vitals. The fix is one line, but the trap is whitespace before the DOCTYPE. This guide covers the fix and the platform-specific gotchas.
<!DOCTYPE html>If the first line is blank, contains a BOM character, contains an XHTML DOCTYPE, or contains anything else — you have a problem.
document.compatModeExpected:
"CSS1Compat" (standards mode). If you get "BackCompat", the page is rendering in quirks mode and your DOCTYPE is wrong or missing.
<!DOCTYPE html> <html <?php language_attributes(); ?>> <head>No blank lines, no whitespace, no PHP echo before the DOCTYPE line. If you're using a child theme, edit the child theme's header.php, not the parent.
<!DOCTYPE html>
<html lang="{{ request.locale.iso_code }}">
Shopify rarely has DOCTYPE issues since theme.liquid is tightly controlled, but custom themes sometimes inject Liquid output before the DOCTYPE.
app/layout.tsx. If you see a DOCTYPE issue on a Next site, the cause is usually middleware or a custom server response that prepends content before Next renders. Audit middleware.ts and any custom response handlers.
function my_function() {
// ...
}
?>
[BLANK LINE]
That blank line after ?> echoes to the response before the DOCTYPE. Fix: remove the closing ?> entirely. PHP doesn't require it and modern coding standards recommend omitting it in PHP-only files.
curl -s https://yourdomain.com/ | head -c 100Expected: response starts with
<!DOCTYPE html> immediately. Any preceding character is a bug.
document.compatMode should return "CSS1Compat".
?> in PHP-only files, (c) DOCTYPE as first non-whitespace content. Catches issues before deploy.Verify the DOCTYPE error is cleared and standards mode is active.
Run HTML Checker →