What is a doctype declaration?
All HTML code must start with a <!DOCTYPE html> declaration, according to HTML5 specifications. Browsers detect the doctype declaration in an HTML file. It signals them to use HTML standards when rendering and displaying the file rather than using other rendering specifications that are not compatible.
In the past, declaring the doctype can become complicated. This is mainly because before web standards were established, separate codes were written for Netscape Navigator and Microsoft Explorer. This changed when W3C created the web standards. However, most websites cannot immediately start using these standards because it would break the web. Up until HTML4, there were three different web layouts used, namely: “quirks mode” – the nonstandard implementation of Netscape and Internet Explorer, “almost standards mode” – where only some specifications were nonstandard, and “full standards mode” – which uses all HTML standards.
Luckily, they simplified the doctype declaration when the HTML5 standards were released. Since most websites are already following the full standards mode at the time of release, there was no reason to use the archaic nonstandard format used in quirk mode anymore. For all modern HTML documents, use the <!DOCTYPE html> declaration to enable full standards mode.
Further Reading:
Quirks Mode and Standards Mode – MDN Web Docs