What is DOCTYPE in HTML5
In This Blog we will discuss what is DOCTYPE which is mostly asked Interview Question
Defination of DOCTYPE
Definition: !DOCTYPE
Defines the Document type ,“ ! ” stands for Exclamation mark and DOCTYPE stands for Document type.
Description: The HTML document type declaration is known as DOCTYPE, is the first line of code required in every HTML or XHTML document. The DOCTYPE declaration is an instruction to the web browser about what version of HTML the page is written in. This ensures that the web page is parsed the same way by different web browsers.
What is Syntax Of DOCTYPE in HTML5 and HTML4
- In HTML 5, the declaration is
<
!DOCTYPE html
>
- In HTML 4, the declaration is
DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/strict.dtd" >
As you can see the syntax, the DOCTYPE for HTML5 is rather the most shortest declaration compared to HTML4 or other XHTML declarations due to lack of references to a DTD like we usually have a DTD URL as an attribute.
Is DOCTYPE is case senstive?
- DOCTYPE html declaration is not a case senstive
- But suggested and recommended is DOCTYPE should be in capital letter
Brefily about DOCTYPE
Till now we have seen how to declare the DOCTYPE and what is DOCTYPE, But we will go more depth into that
- A DOCTYPE declaration appears at the top of a web page before all other elements. According to the HTML specification or standards, every HTML document requires a valid document type declaration to insure that your web pages are displayed the way they are intended to be displayed
- The doctype declaration is usually the very first thing defined in an HTML document (even before the opening tag); however the doctype declaration itself is not an HTML tag.
- If you don't use a doctype in the starting of an HTML document, the browser goes to the quirky mode. In that case, you may find that certain content is not being displayed the way you marked them up. So, it is a good practice to start your HTML document with a doctype
- In the version, HTML 4.01, the usage of DOCTYPE declaration was to create a reference to a document type definition (DTD), since the version HTML 4.01 was completely based on a Standard Generalized Markup Language (SGML).
- The document type definition (DTD) is responsible for specifying the rules for the Standard Generalized Markup Language(SGML) so that the browser processes the content correctly.
- In HTML 5 there isn’t any need for a reference to a document type definition (DTD) because HTML 5 is not based on a Standard Generalized Markup Language(SGML).