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
- Why the doctype declaration matters to browser rendering
- How to write and position the HTML5 doctype
- What can happen when it is omitted or replaced with an old form
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>.