HTML: !DOCTYPE Tag (definitions, syntax and examples)

HTML <!DOCTYPE> Declaration - why do you have to specify it?

HTML: <!DOCTYPE> Tag

{tocify} $title={Table of Contents}

The <!DOCTYPE> tag is an essential element in HTML that specifies the Document Type Definition (DTD) of the HTML document. 

It is the first element in an HTML file and declares the version of the HTML used in the document. 

The <!DOCTYPE> tag is not an HTML tag, but rather an instruction to the web browser about how to interpret the document.

The <!DOCTYPE> declaration is optional in HTML5. However, it is still recommended to include it for backward compatibility with older web browsers. 

In previous versions of HTML, the <!DOCTYPE> declaration was required.

The <!DOCTYPE> declaration consists of a string of characters that identify the type and version of the HTML document. 

The declaration begins with <!DOCTYPE and ends with “ > ”. Inside the declaration, there is a string that identifies the type and version of the HTML document. The string is enclosed in quotation marks.

The most common <!DOCTYPE> declaration used today is for HTML5, which is simply <!DOCTYPE html>. This declaration tells the web browser that the document is an HTML5 document and that it should be rendered in the browser's default mode.

Example: HTML document with doctype declaration

<!DOCTYPE html>
<html>
<head>
<title>Title of the document</title>
</head>

<body>
The content of the document......
</body>

</html>{codeBox}

Syntax

<!DOCTYPE html>{codeBox}

Let's take a look at some of the most common <!DOCTYPE> declarations.

There are different types of <!DOCTYPE> declarations, each indicating the version and type of HTML that the document conforms to. 

1. HTML5

The HTML5 “<!DOCTYPE>” declaration is:

<!DOCTYPE html>{codeBox}

This declaration is used for HTML5 documents and is the simplest declaration. It tells the browser that the document is an HTML5 document and that the browser should use its default rendering mode.

2. XHTML 1.0 Strict

The XHTML 1.0 Strict “<!DOCTYPE>” declaration is:

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">{codeBox}

This declaration is used for XHTML 1.0 Strict documents. XHTML is a stricter version of HTML that adheres to XML syntax rules. 

This declaration includes a reference to the DTD that defines the rules for XHTML 1.0 Strict.

3. HTML 4.01 Strict

The HTML 4.01 Strict “<!DOCTYPE>” declaration is:

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">{codeBox}

This declaration is used for HTML 4.01 Strict documents. This version of HTML is stricter than the HTML 4.01 Transitional version and does not allow the use of deprecated elements and attributes.

4. HTML 4.01 Transitional

The HTML 4.01 Transitional “<!DOCTYPE>” declaration is:

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">{codeBox}

This declaration is used for HTML 4.01 Transitional documents. This version of HTML allows the use of deprecated elements and attributes that were removed in HTML5.

5. HTML 4.01 Frameset

The HTML 4.01 Frameset “<!DOCTYPE>” declaration is:

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Frameset//EN" "http://www.w3.org/TR/html4/frameset.dtd">{codeBox}

This declaration is used for HTML 4.01 Frameset documents. This version of HTML allows frameset elements to create web pages with frames.



In summary, the <!DOCTYPE> tag is an essential element in HTML that informs the web browser about the version and type of HTML used in the web page. 

It is recommended to use it for backward compatibility and different types of <!DOCTYPE> declarations are available, depending on the version and type of HTML used in the document.

Conclusion:

Friends, according to my expertise, I have written complete information to help you with “HTML <!DOCTYPE> Tag” If this post is favourable for you or not, please tell me by commenting.

If you liked this post, do not forget to share it with your friends so they can get information about it.

You can ask us through comments if you still have questions or doubts, I will answer all your questions, and you can contact us for more information.

Please tell us through the comment section if you think we miss anything.

To be published, comments must be reviewed by the administrator.*

Previous Post Next Post