HTML <!DOCTYPE>
Tutorial
The <!DOCTYPE>
declaration is used to inform the web browser about the HTML version being used in the document. It is not an HTML tag, but rather an instruction to the web browser on how to interpret the document.
Usage
The <!DOCTYPE>
declaration is placed at the very beginning of an HTML document, before the <html>
tag. It is written as follows:
<!DOCTYPE html>
This declaration tells the web browser that the document is written in HTML5.
Attributes
Below are the main attributes of the <!DOCTYPE>
declaration:
Attribute | Description |
---|---|
html | Specifies the document type version (e.g. HTML5) |
public | Specifies the public identifier of the document type |
system | Specifies the system identifier of the document type |
When specifying the doctype, the html
attribute is mandatory, while the public
and system
attributes are optional.
Examples
Below is an example of a simple HTML document with the <!DOCTYPE>
declaration:
<!DOCTYPE html>
<html>
<head>
<title>My HTML Document</title>
</head>
<body>
<h1>Hello, World!</h1>
<p>This is a sample paragraph.</p>
</body>
</html>
In this example, the <!DOCTYPE html>
declaration specifies that the document is using HTML5.
It is important to always include the <!DOCTYPE>
declaration at the beginning of your HTML documents to ensure proper rendering and compatibility across different browsers.