Hacker News new | ask | show | jobs
by chrismorgan 1396 days ago
It’s not that you’re allowed to omit the head element (you’re not, and you can’t), but that its start and end tags are optional. Same with the html and body elements. (These remarks apply to HTML syntax only; in XML syntax, which is certainly still a thing, you can (if you care not for validity) omit whatever elements you choose to, only needing some root element.)

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.

2 comments

> It’s not that you’re allowed to omit the head element (you’re not, and you can’t), but that its start and end tags are optional.

That’s like calling a cheese sandwich without any cheese a cheese sandwich.

It's not a sandwich recipe. The bread doesn't matter. The cheese does.
If you omit writing <head> and </head> in HTML syntax, there will still be a head tag in the parsed result.

(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.)

I think they are saying HTML implies the <head> for you - the <title> is still required.
convo was about HTML 5 specifically (the W3C version). I've never heard HTML WHATWG called HTML 5.
> I've never heard HTML WHATWG called HTML 5.

Directly from the specification:

> 1.2 Is this HTML5?

> In short: Yes.

https://html.spec.whatwg.org/multipage/introduction.html#is-...?