DEV Community

Cover image for Why Do We Write <! DOCTYPE html> ?
Islam Sayed for Blue Turtle

Posted on

Why Do We Write <! DOCTYPE html> ?

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".


Why do we write <! DOCTYPE html> ?

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

    </head>
    <body>

    </body>
</html>

<! 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.

Top comments (9)

Collapse
 
dbanisimov profile image
Denis Anisimov

I lived without a DOCTYPE on my site for a year and the only thing that broke was a LinkedIn page scrapper 😒 It's like wearing your pants backwards, you look weird, nobody tells you and you may occasionally be denied access to a fancy restaurant. (not based on a real story)(don't do that)

Collapse
 
islam profile image
Islam Sayed

Hi Denis! Great yet funny analogy 😀

Collapse
 
torpne profile image
Kevin McKenna

I have honestly never even considered what is happening under the covers if it was missed.. that's just known it should be there, so out it in. Thanks for the info!

Collapse
 
islam profile image
Islam Sayed

You are welcome! I will continue writing about such small -yet effective- things we often not considering. So stay tuned! And have a nice day 😉

Collapse
 
ahmedam55 profile image
Ahmed Mahmoud

Thanks for your time and effort!

Collapse
 
islam profile image
Islam Sayed

You're welcome!❤

Collapse
 
islam profile image
Islam Sayed

I agree. Here are some other DOCTYPE kinds other than that of HTML.

Collapse
 
tamermaarouf profile image
Tamer_maarouf

Nice

Collapse
 
islam profile image
Islam Sayed

Thank you!