Skip to main content

HTML Guide

Non-space characters found without seeing a doctype first. Expected “<!DOCTYPE html>”.

A missing or incorrectly placed <!DOCTYPE html> declaration at the very start of your HTML document causes this error.

The <!DOCTYPE html> declaration must be the very first thing in your HTML file, before any HTML code. This declaration tells the browser to use standards mode, ensuring reliable rendering. Without it, browsers may behave unpredictably or trigger quirks mode, and validators will issue an error.

Correct Example:

<!DOCTYPE html>
<html lang="en">
  <head>
    <title>Valid HTML Document</title>
  </head>
  <body>
    <p>Hello, world!</p>
  </body>
</html>

Incorrect Example (doctype missing):

<html lang="en">
  <head>
    <title>Invalid HTML Document</title>
  </head>
  <body>
    <p>Hello, world!</p>
  </body>
</html>

Incorrect Example (doctype not at the very start):

Some misplaced text.

<!DOCTYPE html>
<html lang="en">
  <head>
    <title>Invalid Placement</title>
  </head>
  <body>
    <p>Hello, world!</p>
  </body>
</html>

Always ensure <!DOCTYPE html> is the first line.

Learn more:

Related W3C validator issues