The DOCTYPE is a required preamble at the top of every HTML document. It is not an element. Its only practical job today is to tell the browser to use no-quirks mode (often called standards mode) instead of quirks mode.
Always write <!DOCTYPE html> as the first line, then the <html> root with <head> and <body>.
Baseline · Widely available.
Not deprecated and not experimental. The short HTML5 form is supported in all modern browsers.
Legacy doctypes.
Long HTML 4 / XHTML doctypes are historical. Do not use them in new pages — they can trigger limited-quirks or quirks mode depending on the exact string.
Case-insensitive.
<!DOCTYPE html> and <!doctype html> are equivalent. MDN examples often use lowercase; both are fine.
Syntax
HTML Syntax
syntax.html
<!DOCTYPE html>
No end tag. No attributes in modern HTML. Put it before <html>. That is the only form you need.
Reference
Attributes
The HTML5 DOCTYPE has no attributes. Older SGML-style forms used PUBLIC / SYSTEM identifiers — study only, do not copy into new work.
Form
Description
Try it
<!DOCTYPE html>
Recommended. Short HTML5 doctype; triggers no-quirks mode
Include a proper DOCTYPE so the page is not in quirks mode.
Read document.compatMode after the document is available.
Expect CSS1Compat for a normal HTML5 page.
See BackCompat only if the document is in quirks mode.
Example 4 — Legacy DOCTYPE (Study Only)
Recognize old HTML 4 strings in tutorials. Do not use them for new sites.
HTML
<!-- Legacy — do not use in new projects -->
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN"
"http://www.w3.org/TR/html4/strict.dtd">
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Legacy doctype</title>
</head>
<body>
<p>Prefer the short HTML5 doctype instead.</p>
</body>
</html>
Long PUBLIC/SYSTEM forms are legacy. The short HTML5 doctype is enough.
How It Works
Old specs used a DTD URL after PUBLIC.
Browsers mainly used that string for mode switching, not for loading a DTD today.
Wrong legacy forms can trigger quirks or limited-quirks mode.
Migrate to <!DOCTYPE html> whenever you touch the file.
Edge Cases & Pitfalls
Most DOCTYPE bugs come from putting something above it or copying old DTD strings.
order
Keep it first
Comments or junk before the DOCTYPE can force quirks mode. Only an optional BOM may precede it.
legacy
Skip long DTD forms
HTML 4 / XHTML PUBLIC strings are unnecessary. Prefer <!DOCTYPE html> every time.
semantics
Not a tag you style
There is no </DOCTYPE>, no CSS selector for the declaration, and no global attributes on it.
xhtml
Real XHTML is different
Documents served as application/xhtml+xml always use no-quirks mode. Served as text/html, you still need a doctype.
debug
Check compatMode
Use document.compatMode (and browser console warnings) when layout looks oddly “old.”
Compatibility
Browser Support
DOCTYPE mode switching is core HTML behavior in every browser. It is not a Node.js, Deno, or Bun API.
✓ Baseline · Widely available
<!DOCTYPE html>
All modern browsers honor the short HTML5 doctype and enter no-quirks mode. Always include it as the first line of text/html documents.
98%Global support (approx.)
Google ChromeAll
Full support
Mozilla FirefoxAll
Full support
Apple SafariAll
Full support
Microsoft EdgeAll
Full support
OperaAll
Full support
Samsung InternetAll
Full support
Internet ExplorerAll
Supported
DOCTYPEWidely supported
Bottom line: Always ship . Support is universal; the risk is omitting it or using a quirky legacy string.
Remember
Key Takeaways
Purpose:<!DOCTYPE html> turns on no-quirks (standards) mode.
Placement: first line of the file — before <html>.
Form: short HTML5 only; skip legacy PUBLIC/DTD strings.
Verify:document.compatMode === "CSS1Compat" on a healthy page.
One line: every HTML file should start with <!DOCTYPE html>.
UA style
Default CSS Settings
DOCTYPE has no CSS. It is not in the DOM tree as a styled element. It only selects the document’s rendering mode, which can change how some CSS rules behave.
note.css
/* There is no doctype { … } rule.
Style html, body, and other elements instead. */
html {
/* your page styles */
}
If layout looks wrong for no clear reason, confirm the DOCTYPE is present and document.compatMode is not BackCompat.
Frequently Asked Questions
DOCTYPE is a required preamble at the top of an HTML document. Its job is to put the browser into no-quirks (standards) mode so layout follows modern HTML and CSS rules.
No. It is a document type declaration, not an element. It has no end tag, no content, and no global attributes.
Always use <!DOCTYPE html> (case-insensitive). There is no good reason to use longer legacy doctypes in new pages.
As the first thing in the document (only an optional BOM may come before it). Do not put comments, whitespace-heavy junk, or elements above it if you want reliable standards mode.
A legacy rendering mode that emulates old browser bugs. Missing or certain old doctypes can trigger it. Check with document.compatMode: BackCompat means quirks; CSS1Compat means no-quirks or limited-quirks.
It does not style anything itself. It chooses the rendering mode, which changes how some CSS and layout rules behave.