The Document Type Declaration
You'll learn what <!DOCTYPE html> is and why it's the essential first line of every modern HTML document.
What Is the DOCTYPE?
The Document Type Declaration (or DOCTYPE) is the very first line you write in an HTML file. It looks like this:
<!DOCTYPE html>
This isn't an HTML tag—it's an instruction to the web browser. It tells the browser: "Hey, this document is written in HTML5, so please render it using modern web standards."
Why Does It Matter?
Think of the DOCTYPE like a language setting on your phone. Without it, the browser doesn't know which "dialect" of HTML you're speaking. Browsers can operate in different modes:
- Standards mode: Follows modern HTML, CSS, and JavaScript rules consistently
- Quirks mode: Mimics old, buggy behavior from the 1990s for backward compatibility
By declaring <!DOCTYPE html>, you're switching the browser into standards mode, ensuring your page behaves predictably across all modern browsers.
Where Does It Go?
The DOCTYPE must be the absolute first thing in your HTML file—before even the <html> tag. No spaces, no comments before it.
<!DOCTYPE html>
<html>
<!-- Your page content -->
</html>
Historical Context
Older HTML versions (before HTML5) required long, complicated DOCTYPEs that referenced specific technical documents. HTML5 simplified this to just <!DOCTYPE html>—short, memorable, and forward-compatible.
Key Takeaway: Always start your HTML documents with <!DOCTYPE html> to trigger standards mode and ensure consistent, modern rendering across all browsers.