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.

<!DOCTYPE html>
<html lang="en-GB">
  // rest of content omitted for brevity

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.


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


Previous Article
How to crop image in browser using JIMP?

Related Posts

CSS RGB color codes including hex values
December 07, 2021
1 min
Gulshan Saini

Gulshan Saini

Fullstack Developer



Subscribe to our newsletter!

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

Quick Links

Contact UsBrowserCSSPythonPuppeteer

Social Media