Skip to main content
Syllabus
On this page

HTML Doctypes Reference

Badar KhalilUpdated September 27, 2026 2 min read

HTML Doctypes Reference

The HTML doctype is the very first line of any HTML document, and it tells the browser which version of HTML the page is written in. This HTML doctypes reference explains the modern HTML5 doctype, older legacy doctypes, and why choosing the right doctype prevents rendering bugs across browsers.

What Is a DOCTYPE?

A doctype (short for 'document type declaration') is not an HTML tag — it's an instruction to the browser that determines whether the page renders in standards mode or quirks mode. Without a correct doctype, browsers may render CSS and layout inconsistently.

1. The Modern HTML5 Doctype

DoctypeDescription
<!DOCTYPE html>Simple, case-insensitive doctype used for all modern HTML5 documents

This single line replaced the long, complex doctypes required in earlier HTML/XHTML versions. It triggers standards mode in every modern browser.

2. Legacy Doctypes (HTML 4.01 / XHTML)

DoctypeDescription
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">HTML 4.01 Strict — no deprecated presentational elements allowed
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">HTML 4.01 Transitional — allows some deprecated tags
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">XHTML 1.0 Strict — requires well-formed XML syntax

3. Quirks Mode vs Standards Mode

ModeBehavior
Standards ModeBrowser renders the page according to modern web standards (triggered by <!DOCTYPE html>)
Quirks ModeBrowser mimics old, inconsistent rendering behavior from the 1990s, often triggered by a missing or malformed doctype
Almost Standards ModeA middle ground used by some browsers with minor quirks in table cell sizing

4. Why the Doctype Matters

Skipping the HTML doctype or using an outdated one can cause CSS box model calculations, table layouts, and font rendering to break unpredictably between browsers. Always place <!DOCTYPE html> as the very first line of every HTML document, before the <html> tag.

5. Common Doctype Mistakes

MistakeConsequence
Missing doctype entirelyTriggers quirks mode, causing inconsistent rendering
Doctype placed after other tagsIgnored by the browser, quirks mode is triggered
Using an old XHTML/HTML4 doctype unnecessarilyAdds unneeded strictness without HTML5 feature support

Try It Yourself

Use the example below to see the correct placement of a doctype declaration in a full HTML document.

Try it Yourself HTML
Output

Press Run to execute.

Try it Yourself JAVASCRIPT
Output

Press Run to execute.

Exercise: Fix the Missing DoctypeHTML

The HTML document below is missing its doctype declaration. Add the correct HTML5 doctype as the very first line.

Try it Yourself HTML
Output

Press Run to execute.

Show expected output
The document starts with <!DOCTYPE html> followed by the existing markup.

This is a self-check — compare your result with the expected output above.

Was this page helpful?