HTML <!doctype> Tag

The HTML <!doctype> tag is used for specifying which language and version the document is using. This is referred to as the document type declaration (DTD).

Technically speaking, the <!doctype> tag does not represent an HTML element (there is no <!doctype> element). However, it has been included here, as it is a required preamble to all HTML documents.

Also, it is usually referred to as the "doctype declaration" as opposed to the "doctype tag". Having said that, "tag" is a pretty loose term that tends to be applied quite generically across the web, so I've included it in the list of "HTML tags".


The <!doctype> declaration is written as <!doctype> (no end tag) with the language being specified inserted within the tag. The <!doctype> declaration is case-insensitive (i.e. can be either uppercase or lowercase).

The <!doctype> declaration must go right at the top of the page, before any other HTML code.

Like this: