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)
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)
Hi Denis! Great yet funny analogy 😀
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!
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 😉
Thanks for your time and effort!
You're welcome!❤
I agree. Here are some other DOCTYPE kinds other than that of HTML.
Nice
Thank you!