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

Specifications for the <!doctype> Tag

Here is the <!doctype> element defined in the various specifications:

See the full list of HTML tags

About HTML.am

HTML.am was created in order to provide HTML tools, codes, tutorials, and other resources to help webmasters create and maintain their HTML documents.

HTML.am aims primarily at beginners, but may also be useful to web professionals.

About the HTML Codes

The HTML codes on this website are provided free of charge, for you to use however you wish. Feel free to modify the code to suit your own needs.

My Related Sites

Here are some of my other sites: