Skip to main content
HTML Validation

Start tag seen without seeing a doctype first. Expected “<!DOCTYPE html>”.

About This HTML Issue

The Document Type Declaration (commonly called the “doctype”) tells browsers which version and rules of HTML the document follows. In modern HTML5, the doctype is simply <!DOCTYPE html>. It must be the very first thing in the document — before the <html> tag, before any whitespace-generating content, and before any other elements. The only thing permitted before it is an optional BOM (byte order mark) or whitespace characters.

Without a doctype, browsers fall back to quirks mode, a legacy rendering mode that emulates old, inconsistent browser behavior. In quirks mode, the CSS box model, table sizing, font inheritance, and many other layout behaviors work differently than in standards mode. This can cause your page to render inconsistently across browsers and lead to hard-to-debug visual issues. Including the doctype ensures the browser uses standards mode, giving you predictable, spec-compliant rendering.

This error commonly occurs for a few reasons:

  • The doctype was simply forgotten or accidentally deleted.
  • There is content before the doctype, such as an XML declaration (<?xml version="1.0"?>), a comment, or a server-side include.
  • The doctype is misspelled or uses an older, incorrect format.
  • The file contains a BOM or invisible characters before the doctype that shift it out of position (though the validator may report this differently).

The doctype declaration is case-insensitive — <!DOCTYPE html>, <!doctype html>, and <!Doctype Html> are all valid — but the lowercase-uppercase convention <!DOCTYPE html> is the most widely used.

Examples

❌ Missing doctype entirely

<html lang="en">
  <head>
    <title>My Page</title>
  </head>
  <body>
    <h1>Hello</h1>
  </body>
</html>

The validator sees the <html> start tag but no doctype has appeared yet, triggering the error.

❌ Content before the doctype

<!-- This is my website -->

<!DOCTYPE html>
<html lang="en">
  <head>
    <title>My Page</title>
  </head>
  <body>
    <h1>Hello</h1>
  </body>
</html>

Even an HTML comment placed before the doctype can trigger this warning, because the parser encounters non-doctype content first.

❌ Old or malformed doctype

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html lang="en">
  <head>
    <title>My Page</title>
  </head>
  <body>
    <h1>Hello</h1>
  </body>
</html>

While older doctypes like HTML 4.01 may not always produce this exact error, they can trigger related warnings. The HTML5 doctype is the recommended standard for all new documents.

✅ Correct: doctype as the first line

<!DOCTYPE html>
<html lang="en">
  <head>
    <title>My Page</title>
  </head>
  <body>
    <h1>Hello</h1>
  </body>
</html>

The <!DOCTYPE html> appears first, followed by the <html> tag with a lang attribute, a <head> with a required <title>, and the <body>. This is a minimal, fully valid HTML5 document.

✅ Correct: fragment with doctype added

If you were previously only writing a fragment like <div><p>Hello</p></div>, wrap it in a proper document structure:

<!DOCTYPE html>
<html lang="en">
  <head>
    <title>My Fragment</title>
  </head>
  <body>
    <div>
      <p>Hello</p>
    </div>
  </body>
</html>

Always ensure <!DOCTYPE html> is the absolute first thing in every HTML file you create. It’s a one-line addition that guarantees standards-mode rendering and keeps your document valid.

Find issues like this automatically

Rocket Validator scans thousands of pages in seconds, detecting HTML issues across your entire site.

Help us improve our guides

Was this guide helpful?
🌍 Trusted by teams worldwide

Validate at scale.
Ship accessible websites, faster.

Automated HTML & accessibility validation for large sites. Check thousands of pages against WCAG guidelines and W3C standards in minutes, not days.

Scheduled Reports
API Access
Open Source Standards
$7 / 7 days

Pro Trial

Full Pro access. Cancel anytime.

Start Pro Trial →

Join teams across 40+ countries