Skip to Content

Head closed before its tags

What it is

Browsers and crawlers end the <head> at the first element that only belongs in the body, such as a <div>, an <img> tracking pixel, an <iframe> or stray text. Every tag written after that point is read as part of the body, even though the page’s source shows it inside the head. A page builder’s body code field can also write a tag there. Either way the canonical, robots tag, hreflang links, title or description end up where search engines do not read them.

Why it matters

Google says it stops reading the head  at the first element that does not belong there, and it ignores  a canonical outside the head. Most AI crawlers read pages the same way. A page can then be indexed under the wrong address, shown when a noindex should hide it, or shown in the wrong language, while its source looks correct.

How Asky checks it

Asky parses the raw HTML the way a browser does to find where the head ends. The page is reported when a <title> (outside an SVG), a meta description, a canonical link, a robots or googlebot meta tag, or an hreflang link sits in the body. The finding names the element that closed the head, when there is one, and each tag it pushed out. A tag between </head> and <body> stays in the head and is not reported.

Reported as an error with high severity when the canonical, a robots meta tag or hreflang is in the body, or no title is left in the head, which search engines then never apply; as a warning with low severity when only a second title or the meta description is.

How to fix it

  1. Open the finding to see the element that closed the head and the tags after it.
  2. Open the page in the browser’s element inspector, which shows where the parser placed each tag, and compare it with the page source.
  3. Move the element that closed the head into the <body>, or remove it if a plugin or tracking script added it by mistake. If a vendor script insists on the head, place it after all meta and link tags.
  4. If a tag is written in the body on purpose, delete it there and set it through the page’s SEO settings or the head custom code field.
  5. Once the tags are back in the head, read them again: a leftover noindex or a canonical to another page now applies in full.

Example

On https://example.com/blog/pricing-guide, a chat widget’s <div> in the head ends it before the canonical:

<!-- Before --> <head> <title>SaaS Pricing Guide: Models and Examples</title> <div id="chat-widget"></div> <link rel="canonical" href="https://example.com/blog/pricing-guide"> </head> <!-- After: the widget moves to the body --> <head> <title>SaaS Pricing Guide: Models and Examples</title> <link rel="canonical" href="https://example.com/blog/pricing-guide"> </head> <body> <div id="chat-widget"></div> </body>

← Back to Directives

Last updated on