Doctype

Doctype or document type declaration in html defines the type of web document we are using. Doctype includes the version of HTML and its DTD. Website will not be fully functional without doctype in Internet Explorer lower versions.

Doctype is always declared before HTML opening tag. As per W3C, it is compulsory to define doctype of every webpage. Doctype is not a tag, its just document type representation of a webpage.

As per W3C, it is compulsory to defined Doctype of every webpage.


HTML5 Doctype

Doctype is web standard from HTML3 onwards. HTML3, HTML4, XHTML and HTML5 have doctype declaration. HTML5 Based Doctype is smaller than HTML4 and XHTML based doctypes. No need to specify the DTD and html version.

HTML5 Doctype is also known as 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)

In HTML4, Strict type Doctype include all attributes and HTML Elements. It Doesn't Include Presentation elements like <b>, <i>, <s>, etc. Framesets are not allowed in STRICT Type Doctype


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)

In HTML4, transitional type doctype includes all attributes and HTML Elements. They also Includes Presentation elements like <b>, <i>, <s>, etc. Framesets are also not allowed in Transitional Type Doctype


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

XHTML Doctype was same like html4, but with some different properties.

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>