The first line of code in any HTML or XHTML document is the HTML document type declaration, also known as DOCTYPE. The DOCTYPE declaration tells the web browser what version of HTML the page is written in. This ensures that different web browsers parse the web page in the same way.
What is doctype in HTML?
A document type declaration or doctype is an instruction that tells the browser about the markup language in which the current page is written. The Doctype isn’t a tag or element, it lets the browser know about the version of our standard of HTML or any other markup language that is being used in the document.
A DOCTYPE declaration appears before all other elements at the top of a web page. According to the HTML standards or specification, every HTML document requires a document type declaration to ensure that the pages are displayed in the way they are intended to be displayed.
The DOCTYPE for HTML5 can be written as shown below:
< !DOCTYPE html >
Usage of Doctype: In the version, HTML 4.01, the usage of the declaration of DOCTYPE was to create a reference to a document type definition (DTD), since the version HTML 4.01 was completely based on a Standard Generalized Markup Language(SGML).
The document type definition (DTD) is responsible for specifying the rules for the Standard Generalized Markup Language(SGML) so that the web browser processes the content correctly. But in the HTML version, HTML 5 there isn’t any need of a reference to a document type definition (DTD) because HTML 5 isn’t based on a Standard Generalized Markup Language(SGML).
In HTML 5, the DOCTYPE declaration is only required for enabling the standard mode for writing documents.
Below is a sample HTML code with doctype declaration:
<!DOCTYPE html>
<html>
<head>
<title>HTML Doctypes</title>
</head>
<body>
<p> HTML is very easy.</p>
</body>
</html>
HTML is very easy.
List of some common doctype declaration
1- HTML 5
<!DOCTYPE html>
2-HTML 4.01 Strict
In HTML 4.01 Strict DTD (document type definition), all those attributes and elements are included that don’t appear in frameset documents or that have not been deprecated.
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN"
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Frameset//EN"
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Frameset//EN"
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
In XHTML 1.1 document type definition (DTD),allows the addition of modules.
<frame> and
<frameset>
The elements have been removed from HTML5 and should no longer be used. Therefore, frameset DTD is no longer valid.