HTML Doctypes
In this page:
<!DOCTYPE html>
What is a Doctype?
The doctype declaration is an instruction that tells the browser what document type and markup version to expect, ensuring the browser renders your page layout consistently.
Example: What is a Doctype?
<!DOCTYPE html>
<html>
</html>
Quirks Mode vs. Standard Mode
If a webpage has a missing or incorrect doctype declaration, browsers will switch into 'Quirks Mode'.
In Quirks Mode, browsers render your pages using old, non-standard layout rules to support ancient websites, which will break your modern CSS styles.
Example: Quirks Mode vs. Standard Mode
<!-- Missing doctype triggers Quirks Mode -->
<!DOCTYPE html>
<html>
</html>
The Modern HTML5 Doctype
In older HTML versions, doctypes were long, complex strings that linked to official document type definitions (DTDs). HTML5 simplified this by introducing a short, clean, and easy-to-remember declaration.
Example: The Modern HTML5 Doctype
<!DOCTYPE html>
Historical Legacy Doctypes
Older versions of HTML (like HTML 4.01 or XHTML 1.0) required long, complex doctype strings that linked to W3C definitions to validate your code. While these are obsolete today, understanding them is useful when maintaining older websites.
Example: Historical Legacy Doctypes
<!-- Legacy HTML 4.01 doctype -->
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
<!-- Modern HTML5 doctype -->
<!DOCTYPE html>
Validation and Web Standards
Web standards require every HTML page to start with a valid doctype. Including the doctype is essential for validating your code and ensuring it passes W3C markup validation tests.
Example: Validation and Web Standards
<!DOCTYPE html>
<html lang="en">
</html>
- Forgetting to include the doctype declaration on the very first line of your HTML file.
- Placing HTML comments or spaces above the doctype declaration, causing browsers to switch into Quirks Mode.
- Using long, outdated HTML4 doctype strings in new web projects.
- The doctype is a standard declaration that must be written on line one of your HTML file.
- It tells the browser what HTML version to expect, ensuring the page renders consistently in Standard Mode.
- The modern HTML5 doctype is simple and clean: .
The HTML5 doctype is natively supported by all modern and legacy web browsers.
Chapter Quiz — Complete all 20 topics to unlock
0/20 topics done
Complete these topics first:
- HTML Keyboard Shortcuts
- HTML Browser Support
- HTML Character Sets
- HTML Doctypes
- HTML Audio/Video Reference
- HTML Meta Tags
- HTML ARIA Roles
- HTML Input Validation
- HTML Iframe Security
- HTML Responsive Images
- HTML Web Fonts
- HTML Icon Fonts
- HTML Progress & Meter
- HTML Output Element
- HTML Datalist
- HTML Image Maps
- HTML Browser DevTools
- HTML Validation
- HTML Quiz
- HTML Interview Prep