Body element before the html element | Tech SEO Tests

HTML validation · Document structure

Body element before the html element

An empty body element appears before the html element, so browsers build the page around it and every head tag ends up in the body.

How this page is built

The source of this page starts with the doctype, then an empty <body></body>, and only then the <html> element.

Once the parser has seen a body, everything that follows is treated as body content. The title, meta description and canonical on this page therefore end up in the body, which crawl tools may also report. That is the consequence of this one error rather than a separate mistake.

Why it matters

The html element has to wrap the whole document, with the head first and the body second. When a body tag comes first, browsers create the document structure early and treat everything after it as body content.

Tags that only work in the head, such as the title, meta robots and canonical, are then in the body. Search engines may ignore them, which can change how the page is indexed and shown.

How to check it

View the source and look at what comes straight after the doctype. The W3C Nu HTML Checker reports a body start tag before the html element. Compare the source with the parsed document in browser developer tools to see where the head tags end up.

How to fix it

Make sure the doctype is followed by the html element, then the head, then the body.

Look for templates, plugins or server-side includes that print markup before the main layout starts, such as a banner, a debug message or a tracking snippet.

Back to all tests