In this article, we will discuss the doctype in HTML5. This is a very basic yet important tag in HTML. This is like the heart of HTML. This tag doesn’t have much content and it won’t be a matter of time to finish it. Let’s keep going! Read about Acronym Tag In HTML 5
We may have seen that every HTML document starts with the doctype tag and we may be unsure what it does. We may think this tag doesn’t have any use. If that’s what is on your mind, I guess you are wrong.
All HTML documents must start a with <!DOCTYPE> declaration. The declaration is not an HTML tag. It is an “information” to the browser about what document type to expect.
This is also known as Document Type Declaration. It specifies the HTML version we use. A DOCTYPE declaration appears at the top of a web page before all other elements
According to HTML standards, every HTML document must have specification about the version specification and type. Doctype does this work.
Declaration of Doctype
It is mandatory to write the doctype at the top of the HTML document.
<!DOCTYPE HTML> or <!doctype HTML>
NOTE: This declaration is only for HTML5 and other version declarations are longer.
Points to be noted
- Note that, this tag is case insensitive.
- We saw that it is mandatory to have a version specification. Only when the Doctype is declared, the browser understands that the HTML document is in standard mode. Otherwise, the browser goes into the quirky mode.
- If we don’t use this tag, we may not get the intended output. This is the reason why you should declare this tag.
- Doctype tag doesn’t have an end tag.
- This is also like the parent tag of every tag in the document present and all other tags are child tags.
The browser that supports are,
- Internet Explorer
Layout of HTML
<!DOCTYPE html> <head> <titlt> ...(HTML heading) </title> </head> <body> ... ...(code for your webpage) ... </body> </html
<!DOCTYPE html> <head> <title> Example </title> </head> <body> Hey </body> </html
- The doctype declaration refers to a Document Type Definition (DTD). It is an instruction to the web browser about what version of the markup language the page is written in. The World Wide Web Consortium (W3C) provides DTDs for all HTML versions.
- You Must add a doctype declaration when creating an HTML document. Also, use the W3C’s validator to check your HTML for markup or syntax error before publishing online.
Frequently Asked Questions(FAQ):
HTML5 has only one doctype and its declaration is
HTML5 version has only one doctype.
HTML4 version has three types namely- strict, transitional and frameset
In this article, we discussed the doctype in the HTML5 version. I hope now you understand the importance of this tag. We also discussed the browser supports and other key points related to the doctype. Hope this article helped. Keep learning and happy coding!