HTML Doctype

Learn via video course
FREE
View all courses
JavaScript Course With Certification: Unlocking the Power of JavaScript
JavaScript Course With Certification: Unlocking the Power of JavaScript
by Mrinal Bhattacharya
1000
4.8
Start Learning
JavaScript Course With Certification: Unlocking the Power of JavaScript
JavaScript Course With Certification: Unlocking the Power of JavaScript
by Mrinal Bhattacharya
1000
4.8
Start Learning
Topics Covered

Overview

HTML doctype is the instruction about what version of HTML the page is written in, passed to the web browser. It is used to make sure that it is parsed in a similar way by different web browsers.

!DOCTYPE HTML

A doctype is a document type declaration (DTD), which informs the browser about the document to be expected on the webpage. The HTML doctype is not a tag or element of the HTML; rather, the HTML doctype tells the browser about the specifications like the version of the HTML or the standards.

Note: The HTML doctype is a null element, i.e. it is self-closing and mustn't contain any content within itself.

Doctype Usage

The HTML doctype serves as an instruction to the browser about the markup.

In the 4.01 version of HTML, the refers to Document Type Declaration (DTD). This happens because the 4.01 version of HTML is based on Standard Generalized Markup Language(SGML). Thus the reference is done so that the browser displays the content properly.

A Document Type Declaration is a set of instructions that links with a specific XML or SGML document. In the serialized form of the document, it manifests as a short string of markup that conforms to a particular syntax.

The newer versions of HTML are not based on Standard Generalized Markup Language(SGML). Thus, it doesn't need to refer to Document Type Declaration. Thus, the doctype in the newer version is only used to enable the standard form of writing the documents.

Note: There are multiple types of HTML documents like HTML 4.01 Strict, HTML 4.01 Transitional, HTML 4.01 Frameset, XHTML 1.0 Strict, XHTML 1.0 Transitional, XHTML 1.0 Frameset, XHTML 1.1 etc which may differ a bit in rules and specifications.

Syntax

Following are HTML doctype syntax of some common versions of HTML:

HTML 5

The DOCTYPE in HTML5 is written to enable the standard method of writing. It is case insensitive, i.e., it can be written as <!Doctype HTML>, <!DOCTYPE html> etc. It should be placed on the top of the HTML document.

HTML 4.01 Strict

The DOCTYPE in HTML 4.01 should be placed on the top of the HTML document. The http://www.w3.org/TR/html4/strict.dtd URL is the reference to the document type definition, which includes all the elements and attributes. Here the strict part in the URL means that it does not allow deprecated elements or attributes.

HTML 4.01 Transitional

The DOCTYPE in HTML 4.01 should be placed on the top of the HTML document. The http://www.w3.org/TR/html4/loose.dtd URL is the reference to the document type definition, which includes all the elements and attributes. Here the loose part in the URL means that it may allow some deprecated elements or attributes.

HTML 4.01 Frameset

The http://www.w3.org/TR/html4/frameset.dtd allows HTML 4.01 to use a frameset.

A frameset is an HTML element that contains one or more frame elements. It uses these frame elements to inform the browser about the division of the screen into different split windows and prohibits any content inside the body associated with a page.

XHTML 1.0 Strict

The http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd prevents deprecated tags in the XML document and checks that the code is written in XML Specification.

XHTML 1.0 Strict is the XML equivalent to strict HTML 4.01, and includes elements and attributes that have not been marked deprecated in the HTML 4.01 specification.

XHTML 1.0 Transitional

The http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd allows some deprecated elements in the XHTML.

XHTML 1.0 Transitional is the XML equivalent of HTML 4.01 Transitional and includes the presentational elements (such as center, font, and strike ) excluded from the strict version.

XHTML 1.0 Frameset

The http://www.w3.org/TR/xhtml1/DTD/xhtml1-frameset.dtd allows the frameset in the XHTML.

The XHTML 1.0 Frameset is used when Frames are to partition the browser window into two or more frames. The Frameset DTD includes everything in the transitional DTD plus frames as well.

XHTML 1.1

The doctype in XHTML allows the addition of modules.

This version of XHTML is based on the Strict profile of XHTML 1.0 (often referred to as XHTML 1.0 Strict) with minor changes. Earlier HTML features that had been deprecated were omitted in XHTML 1.1, in order to to provide a consistent, forward-looking document type. In general, the working group's strategy was to define a markup language that is rich in structural functionality but that relies upon style sheets for presentation.

Example

Following is a basic HTML 5 document, with HTML 5 doctype. This is a standard way of writing HTML.

Browser Support

ChromeSafariFirefoxEdgeOpera
!DOCTYPEYES44YES10.50

The column headings have the names of the browsers.

YES means that the browser supports the declaration.

If the row contains a number (for example, 4 for Firefox), it indicates that the browser version specified is the bare minimum required to support the declaration.

Conclusion

  • The HTML doctype is used to instruct the browser that the following document is an HTML document.
  • For earlier versions of HTML, the HTML doctype was used to refer to Document Type Declaration.
  • HTML doctype is added on the top of the document and is case insensitive.