HTML Doctype declaration
This is good practice for HTML documents that start with a <!DOCTYPE> declaration. The HTML <!DOCTYPE> is used to define which version of HTML the document is using.The DTD stands for document-type declaration
<!DOCTYPE> tag is information to the browser about what document type to expect.
The HTML Doctype declaration is an important part of HTML coding. It is a statement at the top of an HTML document that specifies the version of HTML being used in the document. The Doctype declaration is used by web browsers to determine how to render the page.
The Doctype declaration was introduced in HTML 4.01 to provide a way to distinguish between different versions of HTML. The Doctype declaration is mandatory for all HTML documents, and it must be the first thing in the document before any other HTML code.
There are several different versions of the Doctype declaration, each of which specifies a different version of HTML. The most commonly used Doctype declaration is the HTML5 Doctype declaration, which looks like this:
<!DOCTYPE html>
This declaration tells the browser that the document is written in HTML5. The HTML5 Doctype declaration is the simplest Doctype declaration, and it is recommended for all new HTML documents.
Other Doctype declarations include:
<!DOCTYPE HTML PUBLIC “-//W3C//DTD HTML 4.01//EN” “http://www.w3.org/TR/html4/strict.dtd”>
This declaration tells the browser that the document is written in HTML 4.01 Strict. This version of HTML is no longer in use, and it has been replaced by HTML5.
<!DOCTYPE HTML PUBLIC “-//W3C//DTD HTML 4.01 Transitional//EN” “http://www.w3.org/TR/html4/loose.dtd”>
This declaration tells the browser that the document is written in HTML 4.01 Transitional. This version of HTML allowed for some deprecated tags and attributes that were not allowed in the Strict version.
<!DOCTYPE html PUBLIC “-//W3C//DTD XHTML 1.0 Strict//EN” “http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd”>
This declaration tells the browser that the document is written in XHTML 1.0 Strict. XHTML is a stricter version of HTML that requires all tags to be properly closed and all attributes to be quoted. XHTML is no longer in use, and it has been replaced by HTML5.
The Doctype declaration is important because it tells the browser how to render the page. Different versions of HTML have different rules for how tags should be used and how the page should be structured. By specifying the version of HTML being used, the Doctype declaration ensures that the page is rendered correctly.
In addition to specifying the version of HTML being used, the Doctype declaration can also be used to specify the document type, the character encoding, and the language of the document. For example, the following Doctype declaration specifies that the document is written in HTML5, uses UTF-8 character encoding, and is written in English:
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>My HTML Document</title>
</head>
<body>
...
</body>
</html>
Overall, the Doctype declaration is an essential part of HTML coding. It ensures that the page is rendered correctly and helps to maintain compatibility with different web browsers. By using the correct Doctype declaration, web developers can create HTML documents that are both efficient and effective.