<!–
main_leaderboard, all: [728,90][970,90][320,50][468,60]
–>
Declaration HTML <!DOCTYPE>
This post will discuss Tag Doctype with relevant examples and references. This post contains much information that you can use as a learning tool.
The following is an example of a Tag Doctype:
Example
Here is another example of the HTML <!DOCTYPE>:
Example: 
Example Explanation
The code consists of different parts which are as follows:
- <!DOCTYPE html> is a declaration that specifies the version of HTML being used in the document, in this case, it is HTML5.
- <html> marks the beginning of the HTML document and contains all the content of the web page.
- <head> defines the beginning of the head section of the document. This section usually contains information about the document, such as the title of the page.
- <title>Example</title> specifies the title of the document, which appears in the browser’s title bar.
- </head> marks the end of the head section of the document.
- <body> defines the beginning of the body section of the document, which contains the main content of the web page.
- <h1>Hello World!</h1> is a heading tag that defines headings on a web page. It is the top-level heading and displays the text “Hello World!”.
- </body> marks the end of the body section of the document.
- </html> marks the end of the HTML document.
Usage and Definition
It is a requirement that all HTML documents have to begin with the <!DOCTYPE> tag.
Declarations are not HTML tags. It tells the browser what kind of document it is going to receive.
In HTML 5, the Tag Doctype declaration is as follows:
Browser Compatibility
Element | |||||
---|---|---|---|---|---|
<!DOCTYPE> | Yes | Yes | Yes | Yes | Yes |
Earlier HTML Documents
It wasn’t easy to declare in XHTML or HTML 4 documents because it requires a declaration that refers to a DTD (Document Type Definition).
HTML 4.01:
XHTML 1.1:
HTML Doctypes and Elements
You can view our table of all HTML elements in Tag Doctype and see what Doctype each element is.
REMINDERS and TRICKS
Tip: It should be noted that the <!DOCTYPE> declaration is case-insensitive.
Examples
Importance of HTML <!DOCTYPE>
The HTML <!DOCTYPE> declaration is an important element of an HTML document as it specifies the version of HTML being used and the rules that the browser should use to render the page.
The <!DOCTYPE> declaration is always the first line in an HTML document, and it tells the browser which version of HTML the document is written in. This information is important because different versions of HTML may have different rules and syntax, so the browser needs to know which version is being used in order to render the page correctly.
In addition to specifying the HTML version, the <!DOCTYPE> declaration also tells the browser whether the document should be rendered in standards mode or quirks mode. Standards mode is the default mode and is used when the <!DOCTYPE> declaration is present and valid. Quirks mode, on the other hand, is used when there is no <!DOCTYPE> declaration or if the declaration is invalid.
Using the <!DOCTYPE> declaration correctly can help ensure that your HTML code is interpreted correctly by different browsers and devices. It is also an important step in making your code more accessible and compliant with web standards.