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".

Syntax

The <!doctype> declaration is written as <!doctype html> (no end tag). In modern HTML5, this short syntax is all that is required. The <!doctype> declaration is case-insensitive (e.g. <!DOCTYPE html> or <!doctype html>).

The <!doctype> declaration must be placed at the very beginning of the HTML document, before the <html> root tag.

Like this:

Purpose & Best Practices