The DOCTYPE declaration is a line at the very top of an HTML document that tells the browser which rendering mode to use. In modern HTML it is simply <!DOCTYPE html>. It is not an HTML element and is case-insensitive.
Why it matters
Without a valid doctype, browsers fall back to quirks mode, which imitates decades-old behavior. In quirks mode the box model, table sizing, line heights and some layout details differ from the standard, so pages look and behave unpredictably. Older HTML 4 and XHTML doctypes were long strings referencing a document type definition; HTML5 reduced it to a short form that triggers standards mode in every current browser.
Example
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<title>Example</title>
</head>
<body>Hello</body>
</html>
You can check the mode in the console with document.compatMode, which returns "CSS1Compat" for standards mode and "BackCompat" for quirks mode.
Common mistakes
- Putting a comment or whitespace-generating code before the doctype, which can trigger quirks mode in some browsers.
- Leaving it out of templates or generated pages.
- Copying an old XHTML doctype from legacy code.
- Debugging odd layouts without checking the rendering mode.
Related
Get notified when this term updates
Plus occasional practical tips on uptime and monitoring, nothing else. Unsubscribe anytime.
यह पेज सामान्य जानकारी है, जिसे हमारी संपादकीय टीम ने लिखा है और दस्तावेज़ीकरण बदलने पर अपडेट किया जाता है। सर्वर और प्रदाता अलग-अलग होते हैं, इसलिए बदलाव पहले सुरक्षित तरीके से जाँचें। देखें: संपादकीय नीति और अस्वीकरण.