What Are Invalid <head> Elements?#
An invalid <head> element is any element in a page's <head> other than the eight the HTML standard permits there: title, meta, link, script, style, base, noscript and template. When Google meets one — an <img>, an <iframe>, a <div> or even stray text — it treats the <head> as finished and stops reading. Every tag written after that point, including a canonical link or hreflang links, is ignored.
Key Facts (TL;DR)
- Eight valid elements. Only title, meta, link, script, style, base, noscript and template belong in the
<head>. - The first invalid one ends the head. Google assumes the
<head>has ended there and stops reading further elements in it. - Canonical and hreflang are lost. Google accepts both only inside a valid
<head>, so a canonical or hreflang link after the invalid element does nothing. - Tracking snippets are the usual cause. A pixel's
<noscript><img>fallback or an embed pasted into the wrong place is the most common culprit. - The fix is order. Move the element into the
<body>, or at least below every tag Google needs to read.
Which Elements Does Google Accept in the <head>?#
Google uses the HTML standard's list and nothing wider. Its page on valid page metadata states that "the <head> element must only contain the following valid elements (and no other invalid elements), as per the HTML standard" and lists exactly eight. It names iframe and img as common elements that appear in the <head> and make it invalid.
| Valid element | What it is for in the <head> |
|---|---|
<title> | The page title shown in the browser tab and used for search result titles |
<meta> | Character set, viewport, description, robots directives, social tags |
<link> | Canonical URL, hreflang alternates, stylesheets, icons, preloads |
<script> | JavaScript and JSON-LD structured data |
<style> | Inline CSS |
<base> | The base URL relative links resolve against |
<noscript> | A fallback for visitors without JavaScript; inside the head it may hold only link, style and meta |
<template> | Inert markup that scripts clone later |
Anything else is invalid in the <head>: images, iframes, divs, spans, links written as <a>, inline <svg> sprites, form fields, custom elements such as <my-widget>, and any visible text. Text inside a <script>, <style>, <title> or HTML comment is not an element, so a script that spells out "<img>" in a string is harmless.
What Happens When Google Meets an Invalid Element?#
Google stops reading the <head> at the first invalid element. In its own words: "Once Google detects one of these invalid elements, it assumes the end of the <head> element and stops reading any further elements in the <head> element." This is the same thing the HTML parser in every browser does: an element that cannot live in the head closes it, and the parser carries on as if the body had started.
Take this product page. The tracking pixel on line 6 sits above the canonical and hreflang links:
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<title>Blue Running Shoes | Example Store</title>
<noscript><img height="1" width="1" alt="" src="https://tracker.example/pixel.gif"></noscript>
<link rel="canonical" href="https://www.example.com/shoes/blue">
<link rel="alternate" hreflang="de" href="https://www.example.com/de/shoes/blue">
<meta name="description" content="Lightweight blue running shoes.">
</head>
<body>
<h1>Blue Running Shoes</h1>
</body>
</html>Run through a standard HTML parser with scripting off, the <head> of that document ends after the <noscript> start tag. The <img>, both <link> elements and the description <meta> all land in the <body>. Moving the <noscript> to the top of the <body> keeps the pixel working and gives every metadata tag back to the head.
- <meta charset="utf-8">
- <title>Blue Running Shoes</title>
- <noscript><img …></noscript>invalid in the head: Google stops reading here
- <link rel="canonical">ignored
- <link rel="alternate" hreflang="de">ignored
- <meta name="description">ignored
- <meta charset="utf-8">
- <title>Blue Running Shoes</title>
- <link rel="canonical">read
- <link rel="alternate" hreflang="de">read
- <meta name="description">read
- <noscript><img …></noscript>first thing in the <body>
Source: worked example from this article; the stopping rule from Google Search Central, valid page metadata.
Which Tags Stop Working After an Invalid Element?#
The damage depends on which tags come after the invalid element, because Google holds some tags to the <head> strictly and others loosely.
| Tag after the invalid element | What Google says | Result |
|---|---|---|
<link rel="canonical"> | "only accepted if it appears in the <head> section of the HTML" | Ignored |
<link rel="alternate" hreflang> | "must be inside a well-formed <head> section of the HTML" | Ignored |
<meta name="robots"> | "will respect robots meta tags in the body section of an HTML document as well" | Still respected |
| Any other head tag | Google stops reading further elements in the <head> | Not read as head metadata |
The canonical rule comes from Google's guide to consolidating duplicate URLs, which adds "make sure at least the <head> section is valid HTML." A lost canonical means Google chooses the canonical URL itself from the duplicates it finds; see how to use canonical tags properly. A lost hreflang set means Google no longer knows which language version to show which searcher; see how to use hreflang tags correctly. The robots meta tag is the exception, which is why a noindex after an invalid element still works.
What Usually Puts an Invalid Element in the <head>?#
Hardly anyone types an <img> into the head on purpose. It usually arrives with a snippet, a plugin or a template:
- A tracking pixel's noscript fallback. Ad and analytics snippets often ship a
<script>plus a<noscript><img>for visitors without JavaScript, and the whole block gets pasted into the head. - A tag manager's
<noscript><iframe>. These snippets come in two halves: the script for the head and the noscript iframe for the top of the<body>. Pasting both halves into the head puts an iframe there. - Plugins and themes that inject markup. A cookie banner, a chat widget or a promo bar that writes a
<div>, an<svg>icon sprite or a custom element into the head template. - Stray text from a template. A leftover
>from a mistyped tag, a debug string, or an invisible no-break space or byte order mark carried in by an included file. - Elements printed before
<html>. A server-side include or a PHP notice that prints a<div>before the document starts ends the head before a single metadata tag is read.
A <noscript> in the head is itself valid, but the HTML standard allows only link, style and meta inside it there. A parser reading the page without JavaScript — the way a validator reads it — ends the head at the <img>. Google has not published a separate rule for this case, so the strict reading is the safe one: keep images and iframes out of any <noscript> in the head.
How Do You Find an Invalid <head> Element?#
Check the HTML the server sends, not only the page after JavaScript runs. Four ways:
- View Source. Open the page source and read the
<head>from top to bottom. Every element before</head>must be one of the eight valid ones, and there must be no loose text. - Chrome DevTools. In the Elements panel, a canonical or hreflang
<link>that shows up under<body>although the source puts it in the head means something above it ended the head. Chrome runs with JavaScript on, so this view does not reveal an<img>hidden in a head<noscript>; check those in the source. - Google Search Console. URL Inspection shows the HTML Google crawled, so you can read the head exactly as Googlebot received it.
- Greadme Page Audit. The Invalid <head> Elements card appears only when a problem is found, and it names the first invalid element with its line number.
For the example page above, the card reads: "Google stops reading your <head> at <img height="1" width="1" alt="" src="https://tracker.example/pixel.gif"> inside a <noscript> (line 6) and ignores every element after it. Move that <noscript> into the <body>." Because a head template is usually shared by every page, Greadme Site Audit runs the same check on each crawled page and lists every URL that carries the problem.
How Do You Fix Invalid <head> Elements?#
- Move the element into the
<body>. Images, iframes, divs and widgets belong there. A noscript fallback for a pixel or a tag manager goes right after the opening<body>tag. - Delete stray text. Remove the leftover characters, and save included files without a byte order mark.
- Fix the template, not the page. The invalid element nearly always comes from a shared layout, a theme file or a plugin setting, so one fix repairs every page.
- If an element cannot move, put it last. Google strongly recommends not using invalid elements in the
<head>at all, "but if you must, place these invalid elements after the ones you want Google to see." Put the title, meta tags, canonical, hreflang and structured data above it. - Re-test after each fix. Only the first invalid element is reported, because everything after it was already being skipped. A second problem further down can appear once the first one is gone.
The fixed version of the example page:
<head>
<meta charset="utf-8">
<title>Blue Running Shoes | Example Store</title>
<link rel="canonical" href="https://www.example.com/shoes/blue">
<link rel="alternate" hreflang="de" href="https://www.example.com/de/shoes/blue">
<meta name="description" content="Lightweight blue running shoes.">
</head>
<body>
<noscript><img height="1" width="1" alt="" src="https://tracker.example/pixel.gif"></noscript>
<h1>Blue Running Shoes</h1>
</body>How Does Greadme Check the <head>?#
Greadme reads the raw HTML the server returns with a standard HTML parser, the same parsing rules browsers follow, and watches for the first token that closes the head without being </head> or <body>. It parses with scripting off, so an <img> inside a head <noscript> counts. The check is deterministic: the same HTML always gives the same result.
Two details keep it from crying wolf. Both </head> and <body> are optional in HTML, so a page that omits both is never flagged — the first body element simply starts the body. And only the first invalid element is reported, with its line, because that is the point where Google stops. When the problem is found, the Best Practices score loses 10 points; a valid head adds no card and costs nothing.
FAQ#
Is an <img> in the <head> bad for SEO?
Yes, when it sits above tags Google needs. The image itself does no harm, but Google stops reading the head at it, so a canonical link, hreflang links or other metadata written after it are ignored.
Is <noscript> allowed in the <head>?
Yes. It is one of the eight valid elements. Inside the head it may only contain link, style and meta elements, so a noscript holding an image or an iframe belongs at the top of the body instead.
Does an invalid element break my robots meta tag?
No. Google says it respects robots meta tags in the body as well, so a noindex or nosnippet directive still applies. Canonical and hreflang links are the tags that stop working.
Does a script that contains "<img>" in a string count?
No. The contents of script, style and title elements and of HTML comments are text to the parser, not elements, so they never close the head.
Do I get a problem if my page leaves out </head>?
No. The closing head tag is optional in HTML. An element that cannot live in the head simply starts the body. Greadme flags an invalid element only when a </head> or <body> tag still follows it, which proves it was written inside the head.
Why is only one invalid element reported?
Because Google stops at the first one. Everything after it is already being skipped, so the first element is the one to move. Re-run the check after the fix to catch any other element further down.
Conclusion#
The <head> accepts eight elements, and Google stops reading it at the first element that is not one of them. A misplaced pixel, iframe, widget or stray character above your canonical or hreflang links makes Google ignore those links. Keep the head to title, meta, link, script, style, base, noscript and template, move everything else into the body, and run Greadme Page Audit to confirm no invalid element is left.
