HTML <!doctype> Declaration
The <!doctype html> declaration identifies the document as HTML and helps browsers render the page using standards mode. It should appear at the beginning of every HTML document, before the <html> element.
Syntax
<!doctype html>
The declaration is written at the beginning of the document before any HTML elements.
Example
The following example shows the document type declaration in a basic HTML document:
<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8">
<title>HTML Example</title>
</head>
<body>
<h1>Hello, World!</h1>
</body>
</html>
The <!doctype html> declaration appears before the opening <html> tag.
Usage Notes
The <!doctype html> declaration is not an HTML element and does not use an opening and closing tag. It is a special instruction used by browsers when processing an HTML document.
Modern HTML uses the simple <!doctype html> declaration. Older versions of HTML used longer document type declarations that referenced specific document type definitions.
Although HTML syntax is generally ASCII case-insensitive for the DOCTYPE keyword, writing <!doctype html> in lowercase provides a simple and consistent convention for modern HTML documents.
Omitting or using an incorrect document type declaration can cause a browser to render a page in quirks mode instead of standards mode, which may change how HTML and CSS are interpreted and displayed.
Browser Support
The HTML document type declaration is recognized by all modern browsers and should be included at the beginning of every HTML document.
The <!doctype html> declaration does not require a Baseline compatibility status because it is part of the fundamental syntax used to identify an HTML document rather than an optional browser feature.
Related Elements
<html> - Represents the root element of an HTML document and appears immediately after the document type declaration.
<head> - Contains metadata and other information about the HTML document.
<body> - Contains the content displayed as part of the web page.
