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 https://twitter.com 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: https://html.spec.whatwg.org/multipage/syntax.html#syntax-tag-omission

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

the more you know animation

Postmark Image

Speedy emails, satisfied customers

Are delayed transactional emails costing you user satisfaction? Postmark delivers your emails almost instantly, keeping your customers happy and connected.

Sign up

Top comments (0)

A Workflow Copilot. Tailored to You.

Pieces.app image

Our desktop app, with its intelligent copilot, streamlines coding by generating snippets, extracting code from screenshots, and accelerating problem-solving.

Read the docs