HomeTutorsContact

What Is HTML 5 Doctype?

By Gulshan Saini
Published in HTML
July 29, 2020
1 min read

The doctype appears just above <html> tag, at the very start of each HTML document, which is a processing instruction indicating the markup language used in the document.

It allows browsers to correctly interpret which rules have been used to create underlying webpage, and subsequently render them correctly. It also tell spec validators(for example the W3C HTML validator) what type of HTML should be expected and how it should be validated.

Valid HTML5 doctypes

We will be just talking about HTML5 doctypes here as, it is latest and backward-compatible with previous versions of the specification. Doctype declaration is case insensitive, so any of following forms are valid HTML5 doctype declarations <!DOCTYPE html>, <!doctype html>, <!doctype HTML> or even <!doctype Html>.

Is doctype mandatory

Doctype declaration is optional, but it would be useful for preventing browser “quirks mode”. Doctype tells browser to render the page in “standards mode”. The difference between quirks mode and standards mode can mean the difference between a nicely laid-out page and a confusing mess, so, as a result, you should always put your HTML5 file in standards mode by including the doctype.

Doctype should be on the first line of your HTML file. Certain browsers will render your page in quirks mode if their is anything else before it - even a single blank line.

Summary

The main conclusion to draw from this article is that you should start all your HTML documents (i.e. anything that gets served as text/html) with <!DOCTYPE html> as the first thing in the source.

  • Detailed explanation of Quirks, Standard and Almost Standard mode

Tags

#html
Previous Article
How to crop image in browser using JIMP?

Gulshan Saini

Fullstack Developer

Subscribe to our newsletter!

We'll send you the best of our blog just once a month. We promise.

Related Posts

How to Strikethrough text in HTML?

June 22, 2020
1 min
© 2020, All Rights Reserved.

Quick Links

Advertise with usContact Us

Social Media