HomeWeb WorldHTML5Understanding HTML Doctype

Understanding HTML Doctype

HTML Doctype

The very first line of a web page before all other elements is the HTML DOCTYPE declaration. According to the HTML specification or standards, every HTML document requires a document type declaration. This is done to insure that the pages are displayed in the way they are intended to be displayed. However, the DOCTYPE declaration is not an HTML tag despite of being the very first thing that is defined in the HTML document.

The DOCTYPE for HTML5 is very short, and case-insensitive.

<!DOCTYPE html>

Earlier versions of HTML language were SGML-based and hence required a reference to DTD. That is why the earlier versions of DOCTYPE were longer. 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.
<!DOCTYPE html>
<html lang="en">
<head>
    <title><!-- Insert your title here --></title>
</head>
<body>
    <!-- Insert your content here -->
</body>
</html>

 

Different HTML 4.01 Doctypes

Let’s have a look at different DOCTYPE from the previous versions of HTML. Although they are no longer considered as a best practice but they are still a valid way to create DOCTYPE.

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:

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

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:

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

 

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:

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

Warning:The <frameset> and <frame> elements has been removed from HTML5 and should no longer be used. Therefore, frameset DTD is no longer valid.

XHTML 1.0 Strict

This DTD contains all HTML elements and attributes, but does NOT INCLUDE presentational or deprecated elements (like font). Framesets are not allowed. The markup must also be written as well-formed XML.

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

XHTML 1.0 Transitional

This DTD contains all HTML elements and attributes, INCLUDING presentational and deprecated elements (like font). Framesets are not allowed. The markup must also be written as well-formed XML.

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

XHTML 1.0 Frameset

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

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

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:

<!DOCTYPE html PUBLIC “-//W3C//DTD XHTML Basic 1.1//EN” “http://www.w3.org/TR/xhtml-basic/xhtml-basic11.dtd”>

Tip: You must add a DOCTYPE to your HTML/XHTML document and use the W3C’s Validator to check the markup or syntax error before publishing online.

RELATED ARTICLES

Most Popular