References

Beginner-friendly references for web development, with live, editable examples.

The HTML <!DOCTYPE> tag

Element All modern browsers Updated
Quick answer

The <!DOCTYPE html> declaration is the very first line of every HTML document. It is not an element — it tells the browser to use modern HTML and render in standards mode (rather than legacy "quirks mode").

Overview

The <!DOCTYPE> declaration comes before the <html> element and is not itself an element or a tag — it is a directive to the browser. In modern HTML it is simply <!DOCTYPE html>: short, case-insensitive, and required.

Its job is to put the browser into standards mode, where pages follow the modern rendering rules. Omit it and the browser falls back to quirks mode, which emulates the bugs of 1990s browsers and breaks modern layouts in confusing ways.

Because the consequences of leaving it out are so disruptive and so hard to debug, the rule is simple: every HTML document must begin with <!DOCTYPE html> as its very first line.

Syntax

<!DOCTYPE html>
<html lang="en">
  …
</html>

Example

Live example
<!DOCTYPE html>
<html lang="en"><head><title>Doc</title></head><body>Hello</body></html>

More Examples

Best practices

  • Begin every document with <!DOCTYPE html> as the first line.
  • Use the short modern form — there is no need for the long DOCTYPEs of older HTML versions.
  • Remember it triggers standards mode; omitting it causes quirks mode.
  • It is case-insensitive, though <!DOCTYPE html> is the conventional form.

Frequently asked questions

What is the DOCTYPE in HTML?
A declaration at the top of the document that tells the browser to use modern (standards-mode) rendering. In HTML it is <!DOCTYPE html>.
What does do?
It puts the browser in standards mode so the page follows modern rendering rules rather than legacy quirks-mode behavior.
Is the DOCTYPE required?
Yes. Every HTML document should start with it; omitting it triggers quirks mode.
What is quirks mode?
A legacy rendering mode that emulates old browser bugs. The browser enters it when the DOCTYPE is missing, which breaks modern layouts.