HTML <!doctype>

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

In HTML5, the basic tag is written like this <!doctype html> and it must be the first line in the document. As with all HTML tags, the <!doctype> is case-insensitive (i.e. it can be written as <!doctype> or <!DOCTYPE>).

The <!doctype> tag is more appropriately referred to as the "<!doctype> declaration" as it is making a declaration for the rest of the document. It must be located at the top of the document, before any HTML elements. The only things that can precede a <!doctype> declaration is a Byte Order Mark (BOM) followed by any <!-- comments --> (but both of these are optional whereas the <!doctype> is not optional).

Previous versions of HTML required information to communicate which version of HTML the document was using, but in HTML5, this is not required. In fact, HTML5 only requires this tag <!doctype html> for legacy reasons and to ensure that browsers make a best-effort attempt at following the relevant specifications.

Example

Here is an example of <!doctype> declaration usage. Of course, the <!doctype> declaration doesn't actually render on the page, but you can see how it's used.

Source CodeResult

See the full list of HTML tags