Site icon Coding is Love

Why do we need DOCTYPE in html?

doctype html

History

✧ In the old days of the web, pages were written in two versions: One for Netscape Navigator, and one for Microsoft IE.

✧ When the web standards were made at W3C, browsers could not just start using them, as doing so would break most existing sites on the web.

✧ Browsers, therefore, introduced two modes to treat new standards-compliant sites differently from old legacy sites.

✧ Modes were: Quirks Mode and Standards Mode. ✧ For HTML documents, browsers use a DOCTYPE at the beginning of the document to decide which mode to handle.

Doctype

✧ In HTML, the doctype is “required” to ensure that the browser makes a best-effort attempt at following the relevant specifications. ✧ Doctype is “not” an HTML element, rather a special instruction to the browser.

If specified, it has to be at “the beginning” of the HTML document just after the Byte-Order-Mark (BOM) if any.

✧ The DOCTYPE for HTML5 is case-insensitive and can be written as < !DOCTYPE html >

Formats of Doctypes

There are 3 types

Examples

If Doctype is not specified?

Summary

Exit mobile version