In every tutorial you've done, you've probably seen the boilerplate HTML5 document start with <!DOCTYPE html>. But have you ever stopped to wonder why we always need it?
It's true, DOCTYPE tells the browser what type of HTML to load. But that's just the tip of the iceberg.
Back in the day, different browsers interpreted things differently. Content written for Netscape could look completely different on Internet Explorer. Thankfully, with the introduction of web standards, things changed. DOCTYPE became essential to ensure compatibility.
DOCTYPE does more than just identify the HTML type. It also controls how your page renders. There are two main modes: quirks mode and no-quirks mode.
Quirks Mode: If your HTML lacks a DOCTYPE, the browser renders your content in quirks mode. This can lead to unpredictable behavior and inconsistencies across different browsers.
No-Quirks Mode: With the DOCTYPE declaration present, the browser uses established standards for rendering, ensuring consistency across platforms.
So, that's why you always need to include DOCTYPE in modern HTML. It ensures your website renders correctly and consistently.
Hope this was helpful!