- Trending Categories
- Data Structure
- Operating System
- MS Excel
- C Programming
- Social Studies
- Fashion Studies
- Legal Studies
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
Why do we use DOCTYPES in HTML document?
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
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 −
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">
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…
- Related Articles
- Why do we use head tag in HTML Page?
- Why do we use reset button in HTML forms?
- Why do we use the novalidate attribute in HTML?
- HTML Doctypes
- How do we add document title in HTML?
- How do we include a section in an HTML document?
- Why do we use interfaces in Java?
- Why do we use random.seed() in Python?
- Why do we use pandas in python?
- Why do we use brackets in BODMAS?
- Why do we use Convex Mirrors ?
- Why do we use JSON.stringify() method in jQuery?