Your first document
The doctype
See why every HTML document begins with a short doctype declaration and how it keeps browsers in standards mode.
The first line in a modern HTML document is:
<!doctype html>
This is the document type declaration, usually called the doctype.
It tells the browser to render the page using standards mode. Without a recognized doctype, browsers can enter quirks mode, which imitates some old browser behavior so ancient pages do not break.
You do not want quirks mode for a new page.
The doctype is not an HTML element. It has no closing tag and does not belong inside the html element. Put it on the first line, before everything else.
You might see very long doctypes in old documents. Modern HTML only needs this short version. HTML is maintained as a living standard, so you do not need to put a version number in it.
Uppercase and lowercase both work, but this is the form I use:
<!doctype html>
If you forget the doctype, the page may still look fine on screen. That is the trap. Layout quirks from quirks mode are subtle and hard to debug later, especially when CSS enters the picture.
I always start new HTML files from a snippet that includes the doctype on line one. Copying from an old template without it is not worth the risk.
When you validate a page, a missing doctype shows up immediately. Treat that as a hard error, not a warning you can ignore.
HTML5 dropped the old public identifiers and DTD URLs. One short line replaced pages of doctype boilerplate. That is the version you want on every new file you create.
Lesson completed