Technology Programming

What is Doctype in HTML? | Learn Doctype in HTML

HTML Doctype

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>
This will appear like this:

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"
3-HTML 4.01 Frameset
In HTML 4.01 Frameset document type definition (DTD),Frames can be used.
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Frameset//EN"

4-HTML 4.01 Transitional
In HTML 4.01 Transitional document type definition (DTD) allows some older PUBLIC and attributes that have been deprecated.
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"

5-XHTML 1.0 Strict
In XHTML 1.0 Strict document type definition (DTD), deprecated tags aren’t supported and the code must be written according to the XML Specification.
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" 

6-XHTML 1.0 Frameset
In XHTML 1.0 Frameset document type definition (DTD),framesets can be used.
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Frameset//EN" 

7-XHTML 1.0 Transitional
In XHTML 1.0 Transitional document type definition (DTD),deprecated elements are allowed.
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" 

8-XHTML 1.1
In XHTML 1.1 document type definition (DTD),allows the addition of modules.
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN" 

 <frame> and <frameset> The elements have been removed from HTML5 and should no longer be used. Therefore, frameset DTD is no longer valid.
The Bottom Line
A DOCTYPE declaration appears before all other elements on a web page. Every HTML document, according to the HTML specification or standards, requires a valid document type declaration to ensure that your web pages are displayed correctly.
The doctype declaration is usually the first thing defined in an HTML document (even before the opening html> tag), but it is not an HTML tag in and of itself.
See Also