# End of file seen without seeing a doctype first. Expected “<!DOCTYPE html>”.

> Canonical HTML version: https://rocketvalidator.com/html-validation/end-of-file-seen-without-seeing-a-doctype-first-expected-doctype-html
> Attribution: Rocket Validator (https://rocketvalidator.com)
> License: CC BY 4.0 (https://creativecommons.org/licenses/by/4.0/)

Every HTML document must begin with a Document Type Declaration (doctype). The doctype tells browsers which version and standard of HTML the document uses, ensuring they render the page in **standards mode** rather than **quirks mode**. Without it, browsers fall back to quirks mode, which emulates legacy rendering behavior from the early web — leading to inconsistent layouts, unexpected CSS behavior, and subtle bugs that differ across browsers.

Since HTML5, the doctype is simply `<!DOCTYPE html>`. It is case-insensitive (`<!doctype html>` also works), but it **must** appear before any other content in the document, including the `<html>` tag. Even a blank line or whitespace before the doctype can sometimes cause issues in older browsers.

This error can be triggered by several common scenarios:

- **The doctype is completely missing.** The file jumps straight into `<html>` or other markup.
- **The doctype is misspelled.** For example, `<!DOCKTYPE html>` or `<!DOCTYPE hmtl>`.
- **The file is empty or contains only non-HTML content.** The validator reached the end without finding any valid HTML structure.
- **A Byte Order Mark (BOM) or invisible characters** appear before the doctype, which can happen when files are saved with certain text editors.
- **The doctype is placed after other elements**, such as a comment or `<html>` tag.

To fix this, ensure `<!DOCTYPE html>` is the very first line of your file, with no preceding content.

## Examples

### ❌ Missing doctype entirely

```html
<html lang="en">
  <head>
    <title>My Page</title>
  </head>
  <body>
    <p>Hello, world!</p>
  </body>
</html>
```

This triggers the error because the validator never encounters a doctype declaration.

### ❌ Misspelled doctype

```html
<!DOCKTYPE html>
<html lang="en">
  <head>
    <title>My Page</title>
  </head>
  <body>
    <p>Hello, world!</p>
  </body>
</html>
```

The typo `DOCKTYPE` means the validator does not recognize it as a valid doctype.

### ❌ Doctype placed after the `<html>` tag

```html
<html lang="en">
<!DOCTYPE html>
  <head>
    <title>My Page</title>
  </head>
  <body>
    <p>Hello, world!</p>
  </body>
</html>
```

The doctype must come **before** the `<html>` tag, not after it.

### ✅ Correct minimal HTML5 document

```html
<!DOCTYPE html>
<html lang="en">
  <head>
    <title>My Page</title>
  </head>
  <body>
    <p>Hello, world!</p>
  </body>
</html>
```

The `<!DOCTYPE html>` declaration appears on the very first line, followed by the `<html>` tag with a `lang` attribute, a `<head>` containing a `<title>`, and a `<body>` with the page content. This is the minimal structure for a valid HTML5 document.
