HTML - <doctype> Tag



The DOCTYPE, also known as the "document declaration, is the first line of code required in every HTML and XHTMLdocument. 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.

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

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
The <!DOCTYPE> declaration is not case sensitive.
<!DOCTYPE html>
<!DocType html>
<!Doctype html>
<!doctype html>

Example

In the following example, let’s see how we are using the Doctype at the top of an HTML document, as follows −

<!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>

On running the above code, the output window will pop up displaying the text on the webpage.

html_tags_reference.htm
Advertisements