The
<!DOCTYPE>declaration defines the document type and version of HTML that the page is written in.
It helps browsers render the page correctly according to HTML standards.In modern web development, the
<!DOCTYPE html>declaration tells the browser that the document is written in HTML5 — the latest standard of HTML.
Syntax
<!DOCTYPE html>- The declaration must appear at the very top of an HTML document, before the
<html>tag. - It is not case-sensitive (
<!doctype html>also works). - It does not have a closing tag.
Example
<!DOCTYPE html>
<html>
<head>
<title>My First HTML Page</title>
</head>
<body>
<h1>Welcome to My Website</h1>
<p>This page uses HTML5 declaration.</p>
</body>
</html>Output
Browser Output:
(Displays “Welcome to My Website” and the paragraph below it)
Browser Support:
Chrome | Firefox | Edge | Safari | Opera | IE9+ |
|---|---|---|---|---|---|
| ✅ Yes | ✅ Yes | ✅ Yes | ✅ Yes | ✅ Yes | ✅ Yes |
There is no visible effect of <!DOCTYPE> on the page itself — it only affects how the browser interprets the HTML.
Notes
- In HTML5,
<!DOCTYPE html>is simple and universal for all browsers. - In older versions of HTML, doctypes were longer and more complex, e.g.:
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
"http://www.w3.org/TR/html4/loose.dtd">- Using the HTML5 doctype ensures your page is rendered in standards mode, not quirks mode (which can cause inconsistent behavior).
Conclusion
The <!DOCTYPE html> declaration is a small but essential part of every HTML document.
It tells browsers to use the latest HTML5 standards, ensuring consistent display and functionality across all browsers.
Always include it at the top of your HTML files to avoid rendering issues and maintain proper page structure.