DEV Community

Cover image for No <head>, no <body>, no problem?
Derek Enos
Derek Enos

Posted on

No <head>, no <body>, no problem?

I was surprised today when I discovered that the HTML response from does not include a <head> tag (or <body> for that matter), though does include tags (e.g. <meta charset>) that are only valid as children of <head>.

Today I learned that this is ok.

Per the HTML spec:

A head element's start tag can be omitted if the element is empty, or if the first thing inside the head element is an element.

A head element's end tag can be omitted if the head element is not immediately followed by ASCII whitespace or a comment.

Similar applies to <html> and <body>, see:

This Google HTML/CSS Style Guide even recommends omitting all optional tags.

the more you know animation

Top comments (0)

🌚 Browsing with dark mode makes you a better developer.

It's a scientific fact.