<!DOCTYPE html> is the very first line of an HTML document. It tells the browser to render in standards mode rather than quirks mode (an old bug-compatible mode that emulates 1990s browsers).
...
Without the doctype, browsers fall back to quirks mode, which changes layout behavior in surprising ways — most famously the box model:
Quirks mode: width includes padding + border (old IE box model)
Standards mode: width is the content box (CSS spec) — predictable
Other quirks include different handling of line-height in table cells, image spacing, and CSS units. These inconsistencies make your carefully written CSS render differently, so you almost always want standards mode.
In HTML4/XHTML the doctype was a long URL referencing a DTD (Document Type Definition):
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "...dtd">
HTML5 simplified it to just <!DOCTYPE html> — it no longer points to a DTD; it's purely a mode switch the browser recognizes.
Always include <!DOCTYPE html> as the first line.
It's a one-line guarantee that your page uses the modern, consistent rendering rules every CSS tutorial and framework assumes — omitting it leads to baffling, hard-to-debug layout differences.