What is doctype in HTML
What is DOCTYPE?
<!DOCTYPE html> is a declaration placed at the very beginning of an HTML document. It tells the browser which version of HTML the page is written in and how to render it.
Why is it Needed?
Without a DOCTYPE, the browser may switch to Quirks Mode, where it tries to emulate old, non-standard behavior for backward compatibility. This can lead to inconsistent rendering across browsers.
With a proper DOCTYPE, the browser uses Standards Mode, rendering the page according to W3C specifications.
DOCTYPE in HTML5
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>My Page</title>
</head>
<body>
<h1>Hello World</h1>
</body>
</html>In HTML5, the declaration is extremely simple: <!DOCTYPE html>. Earlier versions of HTML had much longer declarations:
<!-- 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">Rendering Modes
| Mode | Description |
|---|---|
| Standards Mode | Browser follows W3C specifications strictly |
| Quirks Mode | Browser emulates old, non-standard behavior |
| Almost Standards Mode | Minor quirks for table cell sizing, otherwise standards |
Key Points
- DOCTYPE is not an HTML tag — it's an instruction to the browser
- It must be the very first thing in the document (before
<html>) - It is case-insensitive:
<!DOCTYPE html>,<!doctype html>,<!Doctype HTML>all work - Omitting it causes Quirks Mode which can break layouts
Important:
Always include <!DOCTYPE html> at the top of every HTML document. It ensures consistent, standards-compliant rendering across all browsers.
Short Answer
Interview readyA concise answer to help you respond confidently on this topic during an interview.