S
last year
Sanjnacountry asked

Why do we use <!DOCTYPE html>

Abhay Jajodia
Expert
last year
Abhay Jajodia answered

The declaration, known as the Document Type Declaration, is essential because it tells the web browser what version of HTML the page is using. This helps the browser interpret the content correctly and consistently.

Here's a bit more context to make it clearer:

  • is placed at the very top of an HTML document.

  • Its primary role is to ensure that the browser acts in "standards mode" and not "quirks mode." This is crucial because quirks mode can cause a page to be rendered with bugs stemming from older browsers.

  • It’s essentially a simple instruction ensuring consistent display regardless of the browser someone is using.

  • For modern web pages crafted in HTML5, simply writing is sufficient, which makes it nice and easy!

Hope this helps clarify things a bit! Feel free to ask if you have more questions or need further explanation.

HTML
This question was asked as part of the Learn HTML course.