What is Doctype Declaration in HTML: Is it Required or Not?

  • Post category:HTML
  • Post author:
  • Post last modified:April 2, 2022
  • Reading time:10 mins read
You are currently viewing What is Doctype Declaration in HTML: Is it Required or Not?

The doctype declaration or document type declaration whatever you call is a crucial part of every HTML document. Many of you don’t know is it required or not? Here is the tutorial I will share its importance, and its purpose. Also, tell you how to define it.

The doctype is required in every HTML document. If you do not mention the declaration browsers will run the document in Quirks mode. It places at the top of the document before starting any tag or elements. The doctype is not case sensitive, which means you can write it in a capital letter or small letter that does not matter.

An HTML doctype tag is used to define the document type declaration. It is an instruction to the browser in which an HTML version is used to create the document. On behalf, the browser renders the document and properly display the document.

What is the Doctype Declaration?

The doctype declaration in HTML is an instruction to the browser which version of HTML is used to create the document. Remember the doctype declaration in HTML is not any kind of HTML tag. Although it writes between angle brackets similar to an HTML tag.

<!Doctype html>

Purpose of Doctype In HTML

Doctype Declaration in html

The purpose of a document type declaration in HTML is very simple. As already says the document type declaration is used to give instruction to the web browsers about the HTML document, Which HTML versions are used to create the current document. That helps the browsers properly organize the document.

The document type declaration in HTML5 is very simple. But if we see the previous versions of HTML, like HTML 4 or XHTML the HTML doctype declaration is very hard and lengthy. It is referred to as a DTD (Document Type Definition).

Doctype Declaration in HTML5

As we already discussed, the declaration of doctype in HTML5 is very short and easy. Here is the example HTML5 doctype declaration. The doctype in HTML5 is not case-sensitive.

<!Doctype html>
<!doctype html>
<!DOCTYPE html>

HTML 4.01 and XHTML Doctype Declaration

The declaration in HTML5 previous versions like HTML 4.01 and XHTML is very complicated and lengthy. And it refers to a Document Type Definition (DTD).

Three possible types of Doctype Declaration in HTML 4 and XHTML.

  1. Strict
  2. Transitional
  3. Frameset

Here is the syntax how to declare Doctype in HTML 4.01 and XHTML.

<!Doctype [Root element] [Publicity] "[Registration]//
[Organization]//[Type] [Name]//[Language]" "[URL]">

Doctype Parameters Explanation

Here we explain the parameters in detail.

  1. Root Element – Root element means the <html> element that contains all other elements in HTML document.
  2. Publicity – The Publicity parameters implies that the document is Publicly available (worldwide users) or Private (locally in system users)
  3. Registration.- The Registration parameter has two types of value, plus (+) and minus(-). The plus sign implies that the developer is ISO registered and the minus sign implies the developer is not registered.
  4. Organization – This implies the HTML or XHTML developer. That is W3C.
  5. Type – The type specifies the document type and it is DTD.
  6. Name – The parameter describing the identifier of DTD.
  7. Language – The language parameter defines the language code that is used to create the document.
  8. URL – The URL defines the Document Type Description.

Doctype Declaration In HTML 4.01

The doctype declaration in HTML 4.01 is not easy as HTML5. It has lots of parameters that explain all the details.

Transitional Type Declaration

This type of declaration IN HTML 4 supports all elements and attributes including deprecated elements.

<!Doctype html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
 "https://www.w3.org/TR/html4/loose.dtd">

Strict Type Declaration

As the name says strict, it supports all elements and attributes but does not support deprecated elements.

<!Doctype html PUBLIC "-//W3C//DTD HTML 4.01//EN"
 "https://www.w3.org/TR/html4/strict.dtd">

Frameset Type Declaration

HTML 4 Frameset type declaration support all elements and attributes including deprecated elements and Frames.

<!Doctype html PUBLIC "-//W3C//DTD HTML 4.01 Frameset//EN"
 "https://www.w3.org/TR/html4/frameset.dtd">

Doctype Declaration In XHTML

The doctype declaration in XHML similar as HTML4. It has also three types of declaration.

Transitional Type Declaration

Transitional type declaration in XHTML similar to HTML 4 Transitional type. It supports all elements and attributes including deprecated elements. But does not support Frames.

<!Doctype html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
 "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

Strict Type Declaration

The Strict type declaration in XHTML supports all elements and attributes but does not support deprecated elements.

<!Doctype html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
 "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">

Frameset Type Declaration

The Frameset type declaration in XHTML supports all deprecated elements and attributes including Frames.

<!Doctype html PUBLIC "-//W3C//DTD XHTML 1.0 Frameset//EN"
 "http://www.w3.org/TR/xhtml1/DTD/xhtml1-frameset.dtd">

Chapter Summary

  • The Doctype is used to define which HTML version is used to create a document.
  • Doctype declarations are not cased sensitive.
  • HTML 5 doctype declarations are very easy and short.
  • There are three possible types of doctype declaration in HTML 4 and XHTML.

Frequently Asked Questions On The Topic

  1. Is Doctype required in HTML?

    Yes, Every HTML document needs to start with a document type declaration.

  2. What is doctype HTML used for?

    Doctype is used to give instructions to web browsers.

  3. What happens if do not declare doctype?

    If you do not declare doctype, browsers will run the document in Quirks mode.

Ashim Khatua

Professionally Web Developer since 2015, And also a Blogger. I am the founder of SiteCodings.com. I love to share my knowledge, which I earned the past few years. I want to share my knowledge with you through my Blog. Keep Reading.

Leave a Reply