Doctypes in HTML
? Doctypes in HTML
A DOCTYPE declaration tells the browser which version of HTML your document is written in. It must be the very first line in your HTML document.
Why is DOCTYPE important?
Ensures the browser renders the page correctly
Switches browser to standards mode instead of quirks mode
Helps with compatibility across different browsers
Common DOCTYPEs in HTML
HTML5 (Modern Standard)
<!DOCTYPE html>The simplest and most common DOCTYPE today
Supports all modern HTML features
Older DOCTYPEs (for reference)
HTML 4.01 Strict
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">XHTML 1.0 Strict
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">Example of a complete HTML5 document with DOCTYPE
<!DOCTYPE html><html lang="en"><head> <meta charset="UTF-8"> <title>My Page</title></head><body> <h1>Hello World!</h1></body></html>Summary
| DOCTYPE | Use Case | Notes |
|---|---|---|
<!DOCTYPE html> | HTML5 documents | Use for all modern web pages |
| HTML 4.01/XHTML | Older versions, legacy code | Mostly obsolete, rarely used now |
Need help understanding quirks mode vs standards mode, or how to fix DOCTYPE-related browser issues?