DOCTYPE

The HTML doctype declaration tells the browser which document mode to use. In modern HTML, <!doctype html> enables standards mode and should be the first line of the document.

What you will learn

Modern HTML5 syntax

<!doctype html>
<html lang="en">
  <head>...</head>
  <body>...</body>
</html>

The declaration is not an HTML element and does not need a closing tag. Put it before the <html> element, with no content before it.

Why it is important

Without a valid doctype, browsers may enter quirks mode to preserve compatibility with old pages. CSS layout and sizing can then behave differently from standards-based pages. The short HTML5 form is the recommended choice for new documents.

Older declarations

HTML 4 and XHTML used longer declarations that referenced a document type definition. You may encounter them in older projects, but new HTML documents normally need only <!doctype html>.

Related pages