The HTML <!DOCTYPE> tag
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
<!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?
<!DOCTYPE html>.