A Document Type Declaration, or DOCTYPE, is an instruction to the Web browser about the version of markup language in which a page is written.
A DOCTYPE declaration appears at the top of a web page before all other elements. According to the HTML specification or standards, every HTML document requires a document type declaration to insure that your pages are displayed the way they are intended to be displayed. The doctype declaration is usually the very first thing defined in an HTML document; however the doctype declaration itself is not an HTML tag.
The DOCTYPE for HTML5 is very short, and case-insensitive.
Doctypes from earlier versions of HTML were longer because the HTML language was SGML-based and therefore required a reference to a DTD, but they are obsolete now. With HTML5 this is no longer the case and the doctype declaration is only needed to enable the standard mode for documents written using the HTML syntax.
You can use the following markup as a template to create a new HTML5 document that uses the latest HTML5 doctype declaration.
ExampleTry this code »
<title><!-- Insert your title here --></title>
<!-- Insert your content here -->
Note: The doctype declaration refers to a Document Type Definition (DTD). It is an instruction to the web browser about what version of the markup language the page is written in. The W3C provides DTDs for all HTML versions.
HTML 4.01 Different Doctypes
The following section contains the different doctypes from the previous version of HTML. Although using the HTML 4.01 doctypes are still a valid way to create DOCTYPE declaration, but they are no longer considered a best practice.
HTML 4.01 Strict
The HTML 4.01 Strict DTD includes all elements and attributes that have not been deprecated or do not appear in frameset documents. For documents that use this DTD, use the following DOCTYPE declaration:
HTML 4.01 Transitional
The HTML 4.01 Transitional DTD includes everything in the strict DTD as well as deprecated elements and attributes but excludes the frameset content. For documents that use this DTD, use the following DOCTYPE declaration:
HTML 4.01 Frameset
The HTML 4.01 Frameset DTD includes everything in the transitional DTD, as well as also allows the use of frameset content. For documents that use this DTD, use the following DOCTYPE declaration:
XHTML 1.1 Doctype
XHTML 1.1 is the most current finalized revision of XHTML 1.0 Strict, introducing support for XHTML Modularization, which means that you can add modules (for example, to provide Ruby support for Chinese, Japanese, and Korean characters).
For documents that use this DTD, use the following DOCTYPE declaration: