Well, the title is precisely the only mandatory element in a valid HTML5 document, even if forgetting it seems harmless.
Well, the title is precisely the only mandatory element in a valid HTML5 document, even if forgetting it seems harmless.
Edit with details from https://www.w3.org/TR/2014/REC-html5-20141028/document-metad...
> Note: The title element is a required child in most situations, but when a higher-level protocol provides title information, e.g. in the Subject line of an e-mail when HTML is used as an e-mail authoring format, the title element can be omitted.
From https://www.w3.org/TR/2014/REC-html5-20141028/document-metad...
> If it's reasonable for the Document to have no title, then the title element is probably not required. See the head element's content model for a description of when the element is required.
So strictly speaking, if it's meant to be used as a traditional web page, you should really have it (obviously), but it's not strictly required.
> If the document is an iframe srcdoc document or if title information is available from a higher-level protocol: Zero or more elements of metadata content, of which no more than one is a title element […].
> Otherwise: One or more elements of metadata content, of which exactly one is a title element […].
So it is required, not just suggested, for a web page, but not for all kinds of html documents; TIL. The parser still tries to parse head contents before body contents even if you omit the head tags, so a doctype followed by title is the shortest valid full page.
I didn't mention the doctype because I believe it isn't strictly speaking an element, just a preamble, but you're right, it's required as well.
Funny thing, when I read “the only mandatory element in a valid HTML5 document”, I interpreted “element” in its generic English sense (piece, thing) rather than its HTML sense (node of type element, as distinct from text/comment/doctype/other-types-only-found-in-XML-syntax nodes).
As far as sources are concerned, the HTML spec is maintained by WHATWG, not W3C. The relevant citations start at https://html.spec.whatwg.org/multipage/semantics.html#docume....
The normative reference on the necessity of <title> is in the content model for the head element:
> If the document is an `iframe srcdoc` document or if title information is available from a higher-level protocol: Zero or more elements of metadata content, of which no more than one is a `title` element and no more than one is a `base` element.
> Otherwise: One or more elements of metadata content, of which exactly one is a `title` element and no more than one is a `base` element.
For the rest, you’re correct: the DOCTYPE is the only always-mandatory thing in a valid HTML document.
That’s like calling a cheese sandwich without any cheese a cheese sandwich.
(This is different from XML syntax, where omitting the start and end tags means omitting the element as a whole so that there will be no head tag in the parsed result.)
Directly from the specification:
> 1.2 Is this HTML5?
> In short: Yes.
— https://html.spec.whatwg.org/multipage/introduction.html#is-...?