Skip to content

An element in `<head>` ends it before its metadata

head-invalid-elementserious
On this page

Why it matters

  • Only some elements belong in <head>: title, meta, link, script, style, base, noscript and template. Google's documentation says that when it meets another one, such as an <img> or an <iframe>, it assumes <head> has ended and ignores the elements after it.
  • Tracking snippets often put a one-pixel <img> or an <iframe> in <head>. Store themes and plugins sometimes print stray text there, such as a no-break space. Everything after it is lost: the canonical address, the robots rules, hreflang links, the description, even the title.
  • Browsers show the page normally, so nobody notices. The metadata is in the HTML, but it is no longer in <head> as a parser reads it.

Example

Wrong
<title>عطر العود الملكي | متجر الواحة</title>
<meta property="og:title" content="عطر العود الملكي | متجر الواحة" />
<meta property="og:description" content="عطر عود ملكي بتركيز عالٍ، في زجاجة من 50 مل." />
<meta property="og:image" content="https://www.example.com/og.png" />
<img src="https://tr.example.com/pixel.gif?id=73" width="1" height="1" alt="" />
<meta name="description" content="عطر عود ملكي بتركيز عالٍ، في زجاجة من 50 مل." />
<link rel="canonical" href="/" />
</head>
Right
<meta property="og:image" content="https://www.example.com/og.png" />
<meta name="description" content="عطر عود ملكي بتركيز عالٍ، في زجاجة من 50 مل." />
<link rel="canonical" href="/" />
</head>
<body>
<img src="https://tr.example.com/pixel.gif?id=73" width="1" height="1" alt="" />

How to fix

Move what does not belong in <head> into <body>, or put the metadata before it:

html
<head>
  <title>عطر العود الملكي | متجر الواحة</title>
  <meta name="description" content="…" />
  <link rel="canonical" href="https://shop.example/ar/عود" />
</head>
<body>
  <img src="https://tr.example.com/pixel.gif?id=73" width="1" height="1" alt="" />
  • A pixel's fallback <img> inside <noscript> is valid in <head>; a bare one is not.
  • Look for text between tags in <head>: an &nbsp;, a stray character, or a plugin's message printed into the template.
  • In a tag manager, add pixels to the body, not to the head.

How we detect

  1. We read the HTML as the server sends it, with the parser browsers use, scripts on (so a <noscript> in <head> is read as text, as browsers read it, and ends nothing).
  2. When <head> ended before the page's own </head> or <body>, we take the element or text that ended it.
  3. We list the metadata the parser then placed in the body: <title>, <meta> with a name, property or http-equiv (not microdata's itemprop), and <link> relations that only mean something in <head>.
  4. We report it only when that list holds something search reads: the title, the description, robots rules, the canonical address or an hreflang link. Open Graph tags and style sheets alone are not reported.

A page that writes neither </head> nor <body> starts its body at its first content, which HTML allows: that is not reported. Elements a script adds to <head> after the page loads are not read here.