What is the purpose of <!DOCTYPE html> at starting of an HTML document?

html

Doctype is required in HTML document for legacy reasons. Its main purpose is to prevent the browser from entering 'Quirks Mode' while rendering the document.

Including the DOCTYPE in a document ensures that the browser makes the best-effort to follow standard specifications. The doctype should be included at the beginning of the HTML document as shown in the example, below.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
<!DOCTYPE html>
<html>
  <head>
    <title>Including Doctype in HTML Document</title>
  </head>
  <body>
    <h1>
      Including Doctype in HTML Document
    </h1>
    <p>
      Welcome to hackinbits.com
    </p>
   </body>
</html>

In HTML5, Doctype's only purpose is to activate the full standard mode.

Share and support us

Share on social media and help us reach more people