Doctype

Doctype, or document type declaration, tells the browser which version of HTML the page is written in and which Document Type Definition (DTD) it should use. It is required for proper rendering and standards compliance; older versions of Internet Explorer may behave unpredictably without it.

The doctype must appear before the opening <html> tag. It is not an HTML element but a directive to the rendering engine. Today all modern web pages should include a correct doctype to avoid quirks mode.

According to the W3C, every HTML document must declare a valid doctype.

Doctype Comparison

TypeDeclarationNotes
HTML5<!DOCTYPE html>Simple, case-insensitive, DTD-less
HTML4 Strict<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">No presentational tags
HTML4 Transitional<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">Allows legacy presentation
XHTML 1.0 Transitional<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">XML-based syntax, must be well-formed

HTML5 Doctype

Doctypes have been part of the web standard since HTML3. All versions—HTML3, HTML4, XHTML and HTML5—begin with a doctype declaration. The HTML5 doctype was intentionally simplified; it omits the DTD and version information, making it both concise and case-insensitive.

Because it has no external DTD, the HTML5 doctype is often referred to as the DTD-less doctype.

HTML5 Doctype


<!doctype html>
<html lang="en">
<head>
	<meta charset="utf-8" >
	<title>HTML5 Doctype</title>
</head>
<body>
		HTML5 Webpage
</body>
</html>

HTML4 Doctype

In HTML4, there are two doctype declarations, Strict Doctype and transitional Doctype. In strict doctype, presentational elements, like b, i, small, u, s are not allowed. But in transitional doctype, presentational can be used. Strict and Transitional are data type declarations.

Doctype in HTML 4(STRICT)

The HTML4 Strict doctype includes only the elements and attributes defined in the strict DTD. It prohibits presentational tags such as <b>, <i>, <s> and does not allow framesets.


Strict Type DOCTYPE in HTML4


<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
<html>
    <head>
        <meta http-equiv="Content-Type" content="text/html; charset=utf-8" >
        <title>HTML4 Webpage</title>
    </head>
<body>
    HTML4 Strict Webpage
</body>
</html>

Doctype in HTML 4 (Transitional)

The HTML4 Transitional doctype permits both structural and presentational elements such as <b>, <i>, and <s>. It was intended to ease migration from legacy markup but still excludes framesets.


Transitional Type DOCTYPE in HTML4


<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
    <head>
        <meta http-equiv="Content-Type" content="text/html; charset=utf-8" >
        <title>HTML4 Webpage</title>
</head>
<body>
    HTML4 Transitional Webpage
</body>
</html>

XHTML Doctype

The XHTML doctype resembles the HTML4 declaration but includes an XML namespace and requires well‑formed, XML-compliant markup. It applies to pages served as XHTML rather than traditional HTML.

Extensible HyperText Markup Language Doctype


<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
     "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
    <head>
        <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
        <title>XHTML Webpage</title>
</head>
<body>
    XHTML Transitional Webpage
</body>
</html>