Why We Write <!DOCTYPE html> ?

1 min read

cover image

Yes, this is for the absolute beginner, and also for those non-beginners who forgot. I am going to look back behinds and re-discover things we take as granted by asking “WHAT”, “WHY”, and “HOW”.

<!DOCTYPE html>
<html lang="en">

<! DOCTYPE html> is the first html tag written at the beginning of any html file. It is not an element and doesn’t has content or closing tag. Its job is to tell the browser that the document being rendered is an HTML document. That’s the reason for its position to be the first thing the browser read.

But what would happen if we didn’t write it?

If browser didn’t find a DOCTYPE declaration, it would enter quirks mode🤔 which is a technique used by browsers to try to support old web pages that has been made for Navigator 4 and Internet Explorer 5. Read about it here.

This means that your website will have different behavior and look with different browsers especially if it has new HTML elements and features.