HTML - <!DOCTYPE> Declartion



The <!DOCTYPE> tag is not actually a tag, it is declartion also known as the "document declaration". It is used to declarare the documentation type of HTML and XHTML to the browsers. With the help of DOCTYPE, a web browser can detect what version of HTML a page is written in. This ensures that the web page is described the same way by different web browsers.

Every HTML document requires a <!DOCTYPE> at the top of the documentation. But the DOCTYPE declaration is not an HTML tag. It gives information to the browser about what document type to accept.

HTML <!DOCTYPE> declaration is not case sensitive. We can declarare the version as we want.

<!DOCTYPE html>
<!DocType html>
<!Doctype html>
<!doctype html>

Try to click the icon run button run button to run the following HTML code to see the output.

HTML <!DOCTYPE> Declartion Example

In the following example, let’s see how we are using the Doctype at the top of an HTML document. In this example we are informing the browser that the document will be in HTML5.

<!DOCTYPE html>
<html>
<head>
   <title>HTML doctype Tag</title>
</head>
<body>
   <p> 
     Doctype declaration is mentioned at the 
     starting of every HTML document. 
   </p>
</body>
</html>

Doctype declaration for different version of HTML and XHTML

The curent version of HTML is 5, and in this tutorial we will learn all the things arround HTML5. In HTML 4.01 or older, the declaration is more complicated because it must refer to a DTD (document type definition). A DTD defines the structure and legal elements of an XML document. In contrast, the DOCTYPE declaration is easier in HTML5 because it no longer requires a reference to the DTD. It is no longer based on SGML.

DOCTYPE declaration in HTML5

<!DOCTYPE html>

DOCTYPE declaration in HTML4.01 Strict

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

DOCTYPE declaration in HTML4.01 Transitional

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

DOCTYPE declaration in HTML 4.01 Frameset

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

DOCTYPE declaration in XHTML 1.0 Strict

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

DOCTYPE declaration in XHTML 1.0 Transitional

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

DOCTYPE declaration in XHTML 1.0 Frameset

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

DOCTYPE declaration in XHTML 1.1

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN" 
    "http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">

Supported Browsers

Tag Chrome Edge Firefox Safari Opera
!DOCTYPE Yes Yes Yes Yes Yes
html_tags_reference.htm
Advertisements