juniorHTML5

What is the purpose of the <!DOCTYPE html> declaration in HTML5?

Updated Apr 28, 2026

Short answer

It is a required preamble that ensures the browser renders the page in 'Standards Mode'.

Deep explanation

In HTML5, the DOCTYPE is no longer linked to a Document Type Definition (DTD) like in HTML 4.01. Its primary function is to prevent browsers from entering 'Quirks Mode', which would render the page using legacy layout rules. It must be the very first thing in your HTML document.

Real-world example

Ensuring a CSS Grid layout looks identical in Chrome, Safari, and Firefox by triggering modern standards rendering.

Common mistakes

  • Thinking it is an HTML tag (it's a declaration) or using the old, long XHTML doctypes in a new project.

Follow-up questions

  • What happens if DOCTYPE is omitted?
  • Is DOCTYPE case-sensitive?

More HTML5 interview questions

View all →