SEO check

HTML Doctype: How to Declare It and Fix a Missing Doctype

The doctype is the first line of every web page. See what it does, how our free report checks it and the quick fix when it is missing.

Free to use 8 min read Updated Oct 2026

What Is the HTML Doctype? The Quick Answer

Quick answer: The HTML doctype is the declaration on the first line of a web page, written <!DOCTYPE html>, and it tells the browser to render the page in standards mode instead of quirks mode. Our report checks that the page the browser builds starts with one. Having it keeps layout predictable and clears a best practices item, but it is not a ranking boost.

  • Pass: the report found a doctype at the top of the rendered page.
  • Fail: no doctype was found, so browsers fall back to quirks mode and may lay the page out like it's decades old.
  • Fix: put <!DOCTYPE html> alone on line one of the template, above the html tag.

Check my website

What Is a Doctype Declaration in HTML?

People call it the html doctype tag, but it isn't a tag. It is an instruction with no closing tag and no attributes, and it never belongs inside head or body. When the parser accepts it, the browser creates a doctype node in the Document Object Model, which you can inspect in the console as document.doctype.

The name is short for document type declaration. In the SGML era, pages pointed at a document type definition, or DTD, that listed the allowed elements. That's why older doctypes carry a doctype public identifier and often a system identifier, a URL ending in strict.dtd or loose.dtd. HTML5 dropped the DTD and kept the doctype only as the standards mode switch.

Don't mix it up with two neighbors: the lang attribute names the language, and the charset declaration says how bytes are decoded. Our charset declaration guide covers the last one.

How to Write the HTML Doctype Declaration

The doctype syntax is a single short line, and it goes first in the file. Here is a minimal page you can copy into a template.

HTML
<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="utf-8">
  <title>Doctype demo</title>
</head>
<body>
  <p>Hello, standards mode.</p>
</body>
</html>

The doctype sits alone on line one, the html root element follows and the charset tag leads off the head. The keyword is case insensitive, so DOCTYPE and doctype both work. Skip any version number, quotes or closing slash.

The HTML Standard doctype section allows comments and whitespace before it, but don't use that freedom. XML generators sometimes print the legacy form <!DOCTYPE html SYSTEM "about:legacy-compat">, which is valid and still gives standards mode, though Lighthouse expects the plain short form and will flag it, so switch to <!DOCTYPE html> if you control the template.

Paste the sample into the Online HTML Viewer, or edit your page in the HTML Editor.

Why the HTML Doctype Matters: Standards Mode vs Quirks Mode

Browsers use one of three rendering modes: no-quirks, which most people call standards mode; limited-quirks, called almost standards mode in older docs; and full quirks. The document.compatMode property returns CSS1Compat for the first two and BackCompat for quirks mode. Quirks mode copies Netscape Navigator 4 and Internet Explorer 5 so old pages keep working. The MDN quirks mode guide explains how the doctype picks the mode.

In our test in headless Chromium, a div set to 24px text held a table. With a doctype the table cell text measured 24px. Without one it dropped to 16px, because quirks mode stops tables inheriting font size. Run document.compatMode in the browser DevTools console to check any page yourself.

Read document.doctype to see the name, publicId and systemId the browser really parsed. Firefox also logs a console warning for quirks mode, so check the Console tab before a validator. The Nu HTML Checker flags a missing doctype too.

Search engines don't reward a page for having a doctype, but you gain stable rendering and a clean Lighthouse result.

How SEO Site Checker Tests Your HTML Doctype

Our free website SEO score checker doesn't search your raw source for the word doctype. A headless Chromium browser loads the page and we serialize the final document.

The rule: the check passes when the first line of the rendered HTML starts with a doctype, tested without regard to letter case.

A pass shows a green tick, a line saying the page has a doctype declaration and a code badge. A fail shows a red icon, a line saying it has none, a red How to Fix button and a Read the Doctype guide link pointing here. The badge always prints the short HTML5 form, so it can't show your version.

The Lighthouse doctype audit also flags a missing doctype. Lighthouse is stricter: it also flags doctypes that push the page out of standards mode and expects the plain short form, so a pass in our report guarantees nothing there.

What passes

  • Any doctype on line one counts, in any letter case, including legacy HTML 4.01 and XHTML forms.
  • A comment, blank lines, an XML declaration or one byte order mark before it still pass.

What fails

  • No doctype declaration at all fails, and so does a typo in the keyword, a doctype with no name or a doctype placed after the html tag.
  • Any stray output printed before the doctype also fails: visible text, an element, a PHP notice or a second byte order mark. The late doctype is ignored.

What the check does not test

  • It doesn't judge the choice. A misspelled name such as htm and an HTML 4.01 Transitional identifier with no URL both pass while still triggering quirks mode, and junk after the name, such as a stray word after html, also passes while still rendering in quirks mode.
  • XHTML served as application/xhtml+xml without a doctype is in standards mode, yet it fails here.

Check my site free

HTML Doctype Types Compared: HTML5, HTML 4.01 and XHTML

This table shows the mode each older doctype triggers.

DoctypePublic identifier containsModeAdvice
HTML5None, just the word htmlStandardsUse it for every new page.
HTML 4.01 StrictDTD HTML 4.01//ENStandardsLighthouse expects the short form, so switch.
HTML 4.01 Transitional with its URLDTD HTML 4.01 Transitional//EN and a URLLimited quirksReplace with the short form.
HTML 4.01 Transitional without URLDTD HTML 4.01 Transitional//EN and no URLQuirksReplace it. Tutorials paste this one.
HTML 4.01 FramesetDTD HTML 4.01 Frameset//ENQuirks, or limited quirks with a URLFrame based pages only.
XHTML 1.0 Strict or 1.1DTD XHTML 1.0 Strict//ENStandardsSwitch to the short form.
XHTML 1.0 TransitionalDTD XHTML 1.0 Transitional//ENLimited quirksReplace with the short form.

Frame based pages are covered in our framesets guide, and old doctypes tend to arrive with font and center tags, which the deprecated HTML tags guide explains.

Where to Add the Doctype in WordPress, Laravel and Static Sites

Each platform prints the page top from a different file.

PlatformFile to checkWhat to look for
Static siteThe top of each .html fileThe doctype alone on line one.
WordPress classic themeheader.php in a child themeThe doctype before the html tag.
LaravelThe layout in resources/viewsThe first line of the Blade layout.
Shopifytheme.liquid and snippetsCustom code printed before the doctype.

On WordPress and Laravel, a common culprit is output printed before the layout starts, for example a notice from functions.php, a plugin or a debug call. The mistakes list below shows what to look for.

Hosted builders such as Shopify, Wix and Squarespace print the doctype themselves, so a failure there usually points to custom code or a theme edit that outputs something first. On Shopify, check theme.liquid and any snippet above the opening tag, and ask platform support if you cannot find it. Keep the charset tag first inside head, as the charset guide above explains.

Common HTML Doctype Mistakes

  • Output before the doctype. Visible text, a PHP notice, a second byte order mark or a non-breaking space pushes the doctype down and the browser ignores it. Plain blank lines and a single byte order mark do not fail our check, but remove them anyway. In PHP they are sent as output before your headers, which can cause the "headers already sent" warning, and keeping the doctype strictly first removes any doubt about how a browser will treat it.
  • A second layout wrapping the page. A nested template can bury the real doctype, so search the raw source for a second opening html tag.
  • A doctype after the html tag, or inside head. This usually comes from pasting a snippet at the top of a template, and the parser ignores a doctype it meets late.
  • A mistyped name. Writing htm instead of html passes our check but renders in quirks mode, so compare the spelling against the short form.
  • An old HTML 4.01 Transitional string. Tutorials paste it without its URL, which means quirks mode.
  • A cached copy. A cache or CDN may serve the old page, so test with a throwaway query string.
  • Trusting view page source alone. It shows the raw file, not the parsed page our report reads.

How to Fix

The short version, the same steps you see when you click How to Fix in your report.

Why this fails: the page the browser built has no doctype, so browsers switch to quirks mode and may lay it out like a very old page. Our report reads the final page, so visible text or a PHP notice printed before the doctype fails it too.

How to fix it:

  1. Open the template or file that prints the very top of the page.
  2. Make line one exactly the short doctype shown below, with nothing above it and the html tag on the next line.
  3. Remove anything printed before it, such as stray echo or print calls, PHP notices and hidden characters from includes.
  4. Check that only one layout prints the doctype.
  5. Save the file, deploy it and purge page, plugin and CDN caches.
HTML
<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="utf-8">
  • WordPress: edit header.php in a child theme, since parent theme edits are lost on update. A block theme has no header.php, so look for a notice, echo or stray byte order mark or non-breaking space printed by functions.php or a plugin.
  • Laravel: put the doctype on the very first line of your Blade layout, for example resources/views/layouts/app.blade.php, and look for debug output, a stray echo or a hidden character above it.
  • Static site or plain PHP: fix the top of the file or the shared header include.
  • Hosted builders: check custom code or theme edits that print output before the page, then ask platform support if you cannot find it.

A classic WordPress theme should open header.php like this. Use the short form, not an old HTML 4.01 or XHTML string:

PHP
<!DOCTYPE html>
<html <?php language_attributes(); ?>>

To confirm the mode, run this in the DevTools console. BackCompat means quirks mode, and CSS1Compat means standards or limited-quirks mode.

JavaScript
document.compatMode

Re-test: purge your caches first, then re-run the free SEO check and confirm the Doctype check shows a green tick.

Re-test my website

Frequently Asked Questions

What does doctype html mean?
The word html after the keyword names the document type, and the whole line tells the browser to render the page in standards mode. It is a declaration, not a tag, and html is a name, not a version number.
Is the doctype required in HTML?
Yes, the HTML Standard lists it as a required preamble. A page still loads without one, but browsers fall back to quirks mode and the layout can change, so treat it as mandatory on every page.
Is doctype html case sensitive?
No. DOCTYPE, doctype and Doctype all work, and so does HTML or html after the keyword. Pick one form and keep it identical in every template, since the choice is style only.
Is the doctype an HTML tag?
No, it is a declaration, not an element. It has no closing tag, no attributes and no content, and it sits before the html element as its own node in the document, not inside any element.
Where should the doctype go in an HTML file?
On the very first line, before the html tag, ideally with nothing at all above it. The spec allows comments before it, but keep it first so no stray output from an include can get in the way.
Why is my doctype not working?
Look for visible text, a PHP notice, a non-breaking space or a duplicate layout printed before it, a doctype placed after the html tag, a typo in the keyword or an old cached page. An HTML 4.01 Transitional doctype pasted without its URL can also trigger quirks mode. View source shows the raw file, so a hidden character may not appear.
Does the HTML doctype affect SEO?
Not directly as a ranking signal, so don't expect a rankings gain from adding one. It keeps the layout stable across browsers and clears a Lighthouse best practices issue, which supports a good experience for visitors.

See how your site scores right now

Paste your address into the free report, then use the How to Fix button on anything that needs work.

Free to use. Results in under a minute for most sites.