The HTML <!DOCTYPE> declaration defines the document type and version of HTML being used, ensuring that browsers render the page correctly. It must appear at the very beginning of an HTML document before the <html> tag. The declaration triggers standards mode in browsers, which helps maintain consistent rendering across different browsers. In HTML5, the declaration is simplified to <!DOCTYPE html>, while older versions required more complex strings.
Examples:
<!DOCTYPE html>
<html>
<head>
<title>HTML5 Document</title>
</head>
<body>
<p>This is an HTML5 document.</p>
</body>
</html>
<!-- For older HTML versions (e.g., HTML 4.01 Transitional) -->
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<title>HTML 4.01 Document</title>
</head>
<body>
<p>This is an HTML 4.01 document.</p>
</body>
</html>
HTML Code:
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>HTML Tutorial - Page 24</title>
</head>
<body>
<h1>HTML Doctype</h1>
<p>The <!DOCTYPE> declaration defines the document type and version of HTML. It must be the first thing in an HTML document.</p>
<!DOCTYPE html>
<html>
<head>
<title>HTML5 Document</title>
</head>
<body>
<p>This is an HTML5 document.</p>
</body>
</html>
<!-- For older HTML versions (e.g., HTML 4.01 Transitional) -->
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<title>HTML 4.01 Document</title>
</head>
<body>
<p>This is an HTML 4.01 document.</p>
</body>
</html>
<nav>
<a href="https://simplilearnat.blogspot.com/p/html-tutorial.html">Home</a> | <a href="https://simplilearnat.blogspot.com/2024/07/html-frames.html">Back</a> | <a href="https://simplilearnat.blogspot.com/2024/07/html-backgrounds.html">Next</a>
</nav>
</body>
</html>
The Output of the above code:
HTML Doctype
The declaration defines the document type and version of HTML. It must be the first thing in an HTML document.
This is an HTML5 document.
This is an HTML 4.01 document.