What is the purpose of the declaration in a webpage?
•6 min read
The <!DOCTYPE html> declaration tells the web browser what version of HTML the page is written in.
It ensures that the browser renders the page correctly according to modern HTML standards (specifically HTML5).
🧠 Purpose:
- Informs the browser that the document uses HTML5.
- Prevents the browser from switching to quirks mode (old, non-standard rendering).
- Helps maintain consistent layout and styling across different browsers.
✅ Syntax Example:
<!DOCTYPE html>
<html>
<head>
<title>DOCTYPE Example</title>
</head>
<body>
<h1>Hello, HTML5!</h1>
<p>This webpage uses the HTML5 doctype declaration.</p>
</body>
</html>
JavaScript⚙️ How It Works:
- The
<!DOCTYPE html>must appear at the very top of your HTML file. - It is not an HTML tag—it’s an instruction to the browser.
- In HTML5, this declaration is simple and universal (unlike older HTML versions which had long doctypes).
🏁 Older vs. New HTML Example
HTML4 Doctype:
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
"http://www.w3.org/TR/html4/loose.dtd">
JavaScriptHTML5 Doctype (Modern):
<!DOCTYPE html>
JavaScriptIn short:
👉 The <!DOCTYPE html> declaration ensures your webpage is displayed using modern, standards-compliant HTML5 rendering across all browsers.


