---
title: "Keep the document head clean so crawlers read your title, canonical and robots tags"
description: "How an iframe or image in the HTML head hides the title, canonical and robots tags from Google, why meta refresh redirects fail, and how to fix a broken head."
canonical_url: https://agentic-readiness-scanner.space.fast/knowledge-base/well-formed-document-head
check_id: A3.11
check_title: "Document head is well-formed"
section: "A3 Content accessibility"
priority: nice_to_have
weight: 1
level_gate: none
depends_on: []
keywords: ["invalid element in head", "canonical tag ignored", "meta refresh redirect SEO", "missing doctype", "charset declaration", "Google valid page metadata"]
author: "Matthias Reinholz"
updated: 2026-11-03
---

# Keep the document head clean so crawlers read your title, canonical and robots tags

> How an iframe or image in the HTML head hides the title, canonical and robots tags from Google, why meta refresh redirects fail, and how to fix a broken head.

Check A3.11 (Document head is well-formed) in section A3, Content accessibility. Priority: nice to have. Weight 1. Helps agents, rarely decisive on its own. Not a level gate. It counts toward its section score.

## In short

Google reads the HTML head only up to the first element that does not belong there, and ignores any metadata after it. One stray iframe or image injected by a tag manager can hide the title, the canonical link and the robots directives. This check scans the raw HTML of product pages in order and fails when that metadata sits after such an element, or when a quick meta refresh turns the page into a redirect. It has weight 1, but a failure here can quietly undo other fixes.

## What this check looks at

The head of an HTML page may contain only eight kinds of element: `title`, `meta`, `link`, `script`, `style`, `base`, `noscript` and `template`. Google's documentation on valid page metadata says it stops reading the head at the first element outside that list. Browsers do the same: when the parser meets an `iframe`, `img` or `div` in the head, it closes the head and starts the body.

The scanner reads the raw HTML of each sampled product page, or of the home page when none were sampled, from top to bottom. It looks for:

- **Misplaced metadata.** A `title`, a `rel=canonical` link, a robots or description `meta` tag, or an `hreflang` alternate that appears after an invalid head element or inside the body.
- **Meta refresh redirects.** A `meta http-equiv="refresh"` with a target URL and a delay of five seconds or less.
- **Quirks mode triggers.** No HTML doctype (`<!doctype html>`) at the start of the document, or an older one. Without it, browsers fall back to quirks mode, a legacy way of rendering pages.
- **Missing character encoding.** No charset in the `Content-Type` header and no charset declaration within the first 1024 bytes.
- **Wrong content type.** A page not served as `text/html` (or `application/xhtml+xml`).

Titles inside inline SVG or MathML are ignored. They are an icon's accessible name, not document metadata. The SVG element itself still ends the head if it sits there.

## Why it matters for AI agents

Assistants answer from search indexes, and those indexes rely on head metadata to decide what a page is. The title names the page in a citation. The canonical link says which URL is the real one. The robots meta tag says whether the page may be indexed or quoted. If a crawler stops reading before it reaches them, none of that applies.

The result is confusing. A store can set a perfect canonical tag and a correct title, see them in the page source, and still find the wrong URL or a generated title in results. The cause is often a script added months later that inserts a tracking pixel at the top of the head.

A meta refresh is a different problem. A page that sends visitors elsewhere after a few seconds is treated by Google as a redirect. The product content on it is not what gets indexed.

## How the scanner decides

Only pages that answered with a 2xx status and a non-empty body are judged. When none did, the check is skipped as not applicable. When product pages were sampled but none could be fetched, it is skipped too.

- **Fail** when any judged page has a meta refresh that names a URL, with a delay of five seconds or less.
- **Fail** when a title, canonical, robots meta, description meta or hreflang alternate appears after an element that does not belong in the head, or inside the body. The message names the element and its byte offset, for example an `iframe` at byte 2,481.
- **Warn** when a page is served with a content type other than `text/html` or `application/xhtml+xml`.
- **Warn** when a page lacks the HTML doctype, or declares no character encoding in the header or within the first 1024 bytes. A charset declared later than that counts as missing, which matches the rule of Lighthouse, Google's page audit tool.
- **Pass** otherwise.

The rules run in that order, so the most serious problem is reported first.

## How to fix it

Put the essentials first and keep everything that is not head material out of the head. The usual culprit is a script that writes markup into the head at the wrong place.

### WordPress and WooCommerce

- View the source of a product page and find the first element in the head that is not one of the eight allowed kinds. Its position tells you which plugin or theme hook printed it.
- Tag manager and consent plugins often add a `noscript` fallback with an `iframe`. The `noscript` element is allowed, but the `iframe` inside it must go right after the opening body tag, which is where Google Tag Manager's own instructions place it. Most such plugins have an option for the body placement.
- SEO plugins print the title, canonical and robots tags early in `wp_head`. Plugins that hook in at a higher priority can push markup in before them. Check plugin settings or ask the plugin author.
- Replace any meta refresh redirect with a real 301, using your host's redirect tool or a redirect plugin.

### Shopify

- Open `layout/theme.liquid` under Online Store, Themes, Edit code. The title, canonical and `content_for_header` should come early in the head.
- Apps and pasted tracking snippets sometimes add images or iframes to the head. Move them into the body, or remove snippets from apps you no longer use.
- Shopify themes from the Theme Store start with a doctype and a charset tag. Keep them as the first lines.

### Any other stack

- Start every page with the HTML doctype.
- Make the charset `meta` tag the first element in the head, or send `charset=utf-8` in the `Content-Type` header.
- Place the title, canonical, robots, description and hreflang tags before any script that might inject markup.
- Configure tag managers and consent tools to inject into the body.
- Use HTTP 301 redirects instead of meta refresh.

## Verify it yourself

Print the start of the raw HTML and read the head in order:

```bash
curl -s https://example.com/product/stoneware-mug/ | head -c 4000
```

The first line should be the doctype. Every element before the closing head tag should be one of the eight allowed kinds. To find the most common offenders quickly:

```bash
curl -s https://example.com/product/stoneware-mug/ | sed -n '1,/\/head>/p' | grep -inE 'iframe|img |div|http-equiv="refresh"'
```

Any match before the end of the head is worth a look. Use the raw response, not the browser's element inspector, because the inspector shows the tree after the browser repaired it.

## Common mistakes

- **Tracking pixels in the head.** A one-pixel image or an iframe from an ad or analytics tool ends the head early.
- **Trusting the element inspector.** The browser moves misplaced metadata into a repaired tree, so everything looks fine there. The raw HTML tells the truth.
- **Late charset declarations.** A long block of inline scripts before the charset tag pushes it past the first 1024 bytes.
- **Meta refresh as a quick redirect.** It works for visitors but tells crawlers the page is a redirect, not content.
- **Serving pages as text/plain or application/octet-stream.** A misconfigured server or cache can do this, and parsers then treat the page as something other than HTML.

## FAQ

### Why does Google ignore my canonical tag?

One common reason is that it is not in the part of the head Google reads. If an element that does not belong in the head appears before the canonical link, Google stops reading the head there. Move the canonical link up, or move the stray element into the body.

### Can I put a noscript tag in the head?

Yes, `noscript` is one of the allowed head elements. But in the head it should hold only `link`, `style` and `meta` elements. An `iframe` or `img` inside a head `noscript` still breaks the head, so those fallbacks belong in the body.

### Is a meta refresh redirect bad for SEO?

Google documents that an instant meta refresh is treated as a permanent redirect and a delayed one as a temporary redirect. Either way, the page with the refresh is not the one indexed. A server-side 301 is clearer and faster.

### Do I still need a doctype in HTML5?

Yes. Without the doctype, browsers render the page in quirks mode, which emulates very old browser behaviour. Lighthouse flags a missing doctype for this reason. The modern doctype is a single short line.

## The fix in one step

Start every page with `<!doctype html>`, declare the character encoding first, and keep the head free of anything but title, meta, link, script, style, base, noscript and template, so crawlers read the title, canonical and robots directives. Never redirect with a meta refresh.

```html
<!doctype html>
<html lang="en">
  <head>
    <meta charset="utf-8" />
    <title>Stoneware Mug 350 ml | Berlin Ceramics</title>
    <link rel="canonical" href="https://example.com/product/stoneware-mug/" />
    <meta name="description" content="Hand-thrown stoneware mug, dishwasher safe, 350 ml." />
    <!-- scripts, styles and other metadata follow. No iframe, img or div in the head -->
  </head>
</html>
```

### Prompt for a coding agent

A scan found pages of this store where the title, canonical, robots or hreflang metadata sits after an element that does not belong in the head (or in the body), a meta refresh redirect, a missing doctype or charset, or a content type other than text/html. Audit the page templates. Make `<!doctype html>` the first bytes of every page and `<meta charset="utf-8">` the first element in the head (or send charset in the Content-Type header). Move any element that is not title, meta, link, script, style, base, noscript or template out of the head. Tag managers and consent tools that inject an iframe, img or div into the head are the usual cause, and they must inject into the body instead. Place the title, rel=canonical, robots meta, description and hreflang links before any script that could inject such an element. Replace any meta refresh redirect with an HTTP 301. Verify by fetching a product page with curl and reading the raw head, not the browser's element inspector.

## Sources and specifications

- [Google: valid page metadata (what Google reads in the head)](https://developers.google.com/search/docs/crawling-indexing/valid-page-metadata)
- [Google: redirects and Google Search (meta refresh)](https://developers.google.com/search/docs/crawling-indexing/301-redirects)
- [Lighthouse: properly defines charset](https://developer.chrome.com/docs/lighthouse/best-practices/charset)
- [Lighthouse: page has the HTML doctype](https://developer.chrome.com/docs/lighthouse/best-practices/doctype)

Source: https://agentic-readiness-scanner.space.fast/knowledge-base/well-formed-document-head (Agentic Readiness Scanner knowledge base, by Matthias Reinholz).
