# Why do we use DOCTYPES in HTML document?

Front End TechnologyHTMLWeb Development

#### BACK-END web Development with php & MySQL

10 Lectures 1 hours

#### The Complete Front-End Web Development Course!

127 Lectures 16.5 hours

#### Front End & Fullstack - React 16.8 +

Best Seller

131 Lectures 12.5 hours

A DOCTYPE is nothing more than a document type declaration, which is a list of guidelines that must be attached to a certain html, xml, or sgxml online document. Because it is required for the HTML version, if the user application experiences any problems at that time, it can be quickly determined that the problem is due to incompatibility between the HTML version and the user's browser.

### Formats Of Doctype

They are three types

• Normal

• Deprecated

• Legacy Tool Compatible

## Why Do We Use DOCTYPE?

The DOCTYPE is declared before the head section in a HTML document. This declaration is not an HTML tag but it acts like the information provided to the web browser on what type of elements and attribute to expect in a HTML document.

This declaration is used in two cases:

• Doctype Sniffing or Switching - To provide the information to web browsers about which rendering mode to use (quirks mode, full standards mode or almost standards mode). The web browser will render the document anyway if a doctype is not declared, but the results may not look as intended due to Doctype Sniffing or Switching.

• To help the markup validators check the validity of these web documents against a particular set of rules. These validators check the syntax of the elements in the HTML document and whether they are correctly used. So this doctype declaration informs these validation services what type of elements to expect.

### Syntax of DOCTYPE for HTML5

Doctype syntax for HTML5 and beyond −

<!DOCTYPE html>


### Syntax for DOCTYPE for Older Versions of HTML

The declaration for DOCTYPE is more complicated in older versions as it must refer to the document type definition.

Furthermore, strict, transitional, or frameset DTD declarations were needed for HTML 4.01 doctypes. Each of these DTDs has a unique use case, which is described below.

Strict DTD − Utilized for websites that do not contain characteristics or components.

Doctype syntax for strict HTML 4.01 −

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


Transitional DTD - Used for web pages that include attributes and elements.

Doctype syntax for transitional HTML 4.01 −

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


Frameset DTD - Used for web pages with frames.

Doctype syntax for frameset HTML 4.01 −

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


### Case Sensitivity

DOCTYPE is not case sensitive. It can be declared in any way possible as long as the spelling and the syntax is same.

<!DOCTYPE html>
<!DocType html>
<!doctype html>
<!docTYPE html>
<!DOCType HTML>


And in many other ways…

Updated on 02-Sep-2022 10:55:02