HTML <!DOCTYPE> Declaration

DOCTYPEs are required for legacy reasons. HTML is responsible for telling a Web browser how text and other objects in a Web Page should appear. As per HTML standards, each HTML document requires a document type declaration (DTD). DOCTYPE is a declaration and always appears at the very top of your documents. If it is omitted, web browsers tend to use a different rendering mode that is incompatible with some specifications. Including the DOCTYPE in a document ensures that the web browser makes a responsible attempt at following the relevant specifications.

The root element that represents the document is the first element in the document. The keywords PUBLIC and SYSTEM represent what kind of Document Type Definition it is . If it is PUBLIC, then this keyword is followed by a restricted form of “public identifier” called FPI (Formal Public Identifier) and If it is SYSTEM, only a system identifier must be given. It states that the XML parser must locate the Document Type Definition (DTD) in a system specific manner.

example

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN"
"http://www.w3.org/TR/html4/strict.dtd">

The above code declares the document to be HTML 4.01 Strict

The DOCTYPE statement indicates the particular version of HTML being used in the document. It is used to check the document for validity. DOCTYPE declaration is not an HTML tag. It is only a declaration and always appears at the first line of your HTML documents.

HTML5 Doctype

<!DOCTYPE html>

Above code is the HTML5 DOCTYPE declaration which is very short, due to its lack of references to a Document Type Definition (DTD) in the form of a URL or FPI (Formal Public Identifier). In HTML5, the formal syntax is defined in upper case letters, even if both lower case and mixes of lower case upper case are also treated as valid. Moreover HTML5 is not based on SGML, uses the DOCTYPE only for mode selection. The declaration is supported in all major browsers.

HTML 4.01 Strict

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN"
"http://www.w3.org/TR/html4/strict.dtd">

It does not allow Framesets, presentational or deprecated elements.

HTML 4.01 Transitional

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
"http://www.w3.org/TR/html4/loose.dtd">

Transitional DTD allows some older PUBLIC and attributes that have been deprecated, Framesets are not allowed.

HTML 4.01 Frameset

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Frameset//EN"
"http://www.w3.org/TR/html4/frameset.dtd">

Framesets allowed, and all elements and attributes are equal to HTML 4.01 Transitional

XHTML 1.0 Strict

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">

Framesets are not allowed and it does NOT INCLUDE presentational or deprecated elements

XHTML 1.0 Transitional

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

Framesets are not allowed and it INCLUDING presentational and deprecated elements

XHTML 1.0 Frameset

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Frameset//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-frameset.dtd">

It is equal to XHTML 1.0 Transitional, but allows the use of frameset content.

XHTML 1.1

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN"
"http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">

It is equal to XHTML 1.0 Strict, but allows you to add modules