What is DOCTYPE?


You’re happy and excited because of a hard work on your web page, seems, that you did everything as a pro. Despite you wrote good CSS and XHTML and used a right specification for DOM, your site looks like a rotten egg in any kind of browser. Do you know what is wrong? Probably, it’s hard to believe but the answer is a wrong DOCTYPE header.

You can easily specify the document type definition (DTD) with the help of a doctype element. Although there are several versions of HTML, the doctype is necessary for the browser to help it to understand what type of web page it is. You need to set in the first line of a code to avoid various browser confuses and to show it according to what kind of standard a web page should be displayed.

A DOCTYPE tag is a key point of a web page, moreover, your code and CSS won’t be validated without a DOCTYPE element. In case, you use an incomplete or an obsolete DOCTYPE tag, or do not use this tag at all, your browser will set a quirks mode, hence, your web page will be disassembled by the rules of a backward compatibility.

The kinds of DOCTYPE

There are various kinds of DOCTYPE elements, and they differ depending on the language version you’re targeting.

  • HTML 4.01. Strict and Transitional syntax systems and frameset are used for HTML 4.01, hence, make sure you’ve got the right method. For example, this is the way you should show up a transitional HTML syntax.
  • HTML 5. HTML 5 allows you to do everything at ease, so, provides you with a for all possible documents.
  • XHTML 1.0.XHTML allows you to learn 3 kinds of DOCTYPE elements as well. So, there are strict and transitional XHTML syntax systems and a straight XHTML document with a frameset. For this issue you need to use the following kind.
  • XHTML 1.1. The XHTML developers think that it will push out the HTML in some time. Therefore, this definition has no division and has the only one syntax that follows clear rules.

Related terms: CSS, HTML, XHTML, DOM, DTD, quirks more.

References and further reading: