Doctype in HTML

HTML doctype is the instruction about what version of HTML the page is written in, passed to the web browser. It is used to make sure that it is parsed in a similar way by different web browsers.

doctype is a document type declaration (DTD), which informs the browser about the document to be expected on the webpage.

Doctype Usage

The HTML doctype serves as an instruction to the browser about the markup.

In the 4.01 version of HTML, the refers to Document Type Declaration (DTD). This happens because the 4.01 version of HTML is based on Standard Generalized Markup Language(SGML). Thus the reference is done so that the browser displays the content properly.

Document Type Declaration is a set of instructions that links with a specific XML or SGML document. In the serialized form of the document, it manifests as a short string of markup that conforms to a particular syntax.

The newer versions of HTML are not based on Standard Generalized Markup Language(SGML). Thus, it doesn’t need to refer to Document Type Declaration. Thus, the doctype in the newer version is only used to enable the standard form of writing the documents.

Syntax:

<!DOCTYPE html>

Example

Following is a basic HTML 5 document, with HTML 5 doctype. This is a standard way of writing HTML.

<!-- The DOCTYPE is mentiond on the TOP of the document and it tells the browser that the document is a HTML document -->
<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Html links</title>
</head>
<body>
    <p>This is a basic HTML document.</p>
</body>
</html>