Neova高级 SEO 平台

head 不是 HTML 中的第一个元素

在 Neova 中 直接在抓取过程中运行,无需任何设置。

规则最近审核:2026年10月17日 · 指南更新:2026年7月1日

HTML 标准规定 head 位于 html 内的第一个位置。在它之前的元素可能让解析器结束 head,因此其后的元数据可能被遗漏。

您可以做什么

把 head 开始标签之前的元素移到 body 中,让 head 紧跟在 html 开始标签之后。

Neova 为何标记

  • HTML 标准要求 head 是 html 中的第一个元素。
  • 对解析器来说,head 之前的元素会开启 body,head 及其元数据可能因此落到错误的位置。
  • 搜索引擎从 head 中读取元数据,落到 body 中的 title 或 canonical 可能被遗漏。

来源

完整指南

这一部分目前只有英文版。

Element Code: HT-039

TL;DR: Per the HTML spec, head has to be the first child inside html, before body. When something (a stray tag, a script, whitespace from a template bug) sits in front of it, browsers and crawlers start guessing where your metadata actually lives, and guessing is not a plan. Fix the source order and it goes away.
Element Code
HT-039
Category
HTML structure
Impact
Metadata parsing risk
Detection
View source, validator
Fix effort
Low, template fix

What This Issue Actually Is

The HTML standard defines a strict document structure: <html> contains exactly one <head> followed by exactly one <body>, in that order, with head coming first. This check flags pages where something other than head appears as the first content inside html, commonly a stray text node, an errant <script> tag, an HTML comment placed oddly by a template engine, or in the worst cases actual visible markup like a <p> or <div> sitting ahead of the head element in source order.

This usually is not something a developer typed on purpose. It creeps in from CMS templates that inject a tracking snippet or an ad script above the doctype-to-head boundary, from server-side includes that leave a stray newline-plus-comment before the head tag, or from broken conditional logic that outputs a fragment before the rest of the document assembles. It is a source-order bug, not a visual one, so it is easy to ship without anyone noticing in a normal browser preview.

Why This Matters

Browsers run HTML through an error-correction algorithm defined in the parsing spec, so a page with head not first will usually still render something reasonable, browsers are extremely forgiving and will silently move things around to build a valid DOM. That forgiveness is exactly the problem: it means the bug can sit in production for months with zero visible symptom while quietly putting your metadata parsing at risk.

The real danger is with crawlers and less-forgiving parsers. If non-head content such as a paragraph or an image appears before your actual head element and its metadata, some crawlers and validators will treat that as the effective end of head, meaning your title tag, meta description, canonical, hreflang, and structured data that were meant to live in head can end up interpreted as being inside body instead, where they are not supposed to be and may not be honored the way you intended. Screaming Frog's SEO Spider calls this out explicitly as a validation issue for exactly that reason, metadata correctness depends on the parser reliably knowing where head ends and body begins.

There is also a second-order cost: pages with malformed head boundaries are more likely to have duplicate head elements too, since whatever broke the ordering often also duplicates a script or meta block during the same templating failure. I have traced more than one "our meta description keeps reverting" ticket back to two head-shaped blocks fighting for the browser's attention, and it always starts with a source-order bug like this one.

Correct vs Broken Source Order

Broken <html> <!-- stray include --> <head> <title>...</title> </head> <body> ... </body> </html>

Correct <html> <head> <title>...</title> </head> <body> ... </body> </html> head is first child

How to Detect It

Start with view-source on the raw HTML response, not the rendered DOM in DevTools, DevTools shows you the browser's already-corrected version, which hides the bug you are trying to find. Search the raw source for anything between <html> and <head> that is not pure whitespace.

Screaming Frog SEO Spider flags "Head Not First In HTML Element" directly as a validation issue during a crawl, running your whole site through it is the fastest way to find every affected template at once rather than checking pages one at a time. The W3C Markup Validator and other HTML validators will also catch this as a structural error if you paste in raw source. Because this bug tends to come from a shared template or include, if you find it on one page, crawl the site to see how many templates it touches, it is rarely isolated to a single URL.

Server logs and Googlebot's rendered HTML (available via the URL Inspection tool in Search Console, "View Crawled Page") are worth checking too, comparing what you sent against what Google says it received tells you whether the parser correction is masking the bug for search engines the same way it does for browsers.

How to Fix It, Step by Step

  1. Pull the raw HTML source, not the DevTools-rendered DOM, and locate exactly what sits between the opening <html> tag and the opening <head> tag.
  2. Identify the source. Common culprits: a server-side include or partial injected above the head block, a tag manager snippet pasted in the wrong template region, leftover debug output, or a templating engine emitting a stray comment or newline from a conditional block.
  3. Move the offending content to where it belongs, inside head if it is a script or meta tag meant to be there, or removed entirely if it is debug leftovers or a misplaced include.
  4. Check for a duplicate head while you are in the template, this bug often travels with a second head-like block elsewhere in the page.
  5. Validate the fixed template against the raw source, confirm head is now the literal first child of html with nothing but the doctype and opening html tag ahead of it.
  6. Re-crawl the site to confirm the fix propagated across every page using that template, not just the one you tested by hand.

Where This Commonly Comes From

Source Typical Fix
Tag manager snippet pasted above head Move script into head, or use the container's native head injection slot
Server-side include or partial Reorder the include chain so head loads first
Templating engine stray comment/whitespace Trim conditional output, confirm no leading text nodes
CMS plugin auto-inserting markup Configure plugin's injection point, or disable and hardcode instead
Debug or logging output left in template Remove entirely before deploy
DO

  • Check raw source, not the DevTools-rendered DOM
  • Confirm head is the literal first child of html
  • Crawl the whole site once you find it on one page
  • Compare your source against Googlebot's rendered HTML in Search Console
  • Check for a duplicate head block while you are fixing this
DON'T

  • Assume it is fine because the page looks normal in a browser
  • Only check the rendered DOM, it hides the actual source-order bug
  • Paste tracking snippets above the head tag without checking placement
  • Treat it as fixed after patching just one page of a shared template
  • Ignore it because "browsers handle it," crawlers and validators are less forgiving

FAQ

If My Page Looks Fine in the Browser, Do I Really Need to Fix This?
Yes. Browsers auto-correct malformed source order using their built-in parsing algorithm, so visually you will not notice anything wrong. The risk sits with how crawlers and validators interpret your metadata boundary, not with what a human sees on screen, so a clean visual render tells you nothing about whether this is fixed.
Can This Actually Cause My Title Tag or Meta Description to Be Ignored?
It can, in the specific case where visible markup like a paragraph or div sits ahead of your intended head block. Some parsers treat that as the natural end of head, so real metadata sitting after it can end up read as body content instead. Comments and whitespace alone are less likely to trigger this, but non-whitespace elements are a genuine risk.
Is This the Same Issue as Having Two Head Elements?
Related but not identical. Head not first is a source-order problem, something appears before head. Duplicate head is a count problem, head appears more than once. In my experience they often show up together because both usually trace back to the same broken include or template injection.
How Do I Check the Raw Source Instead of the Rendered DOM?
Use view-source in your browser or curl the URL directly, both give you exactly what the server sent before any browser correction happens. DevTools' Elements panel shows the corrected DOM after parsing, which is the wrong place to look for this specific bug.
Which Crawlers or Tools Actually Flag This?
Screaming Frog SEO Spider surfaces it directly as a validation issue during a standard crawl. General HTML validators, including the W3C Markup Validator, will flag it as a structural error too. It is worth adding to a recurring crawl schedule rather than a one-time check, since it tends to reappear after template or plugin updates.

Tools

  • View source / curl: the only reliable way to see true source order before browser correction
  • Screaming Frog SEO Spider: flags head-not-first as a validation issue during crawl
  • W3C Markup Validator: structural HTML validation against the spec
  • Search Console URL Inspection: compare your source to Googlebot's rendered/crawled HTML
Want your templates checked for structural HTML issues like this one across the whole site?

在您自己的网站上找到它

Neova 在每次抓取时都会运行此检查项和其他所有检查项,然后把修复方法写成工单交给您的团队。

  • 适用于 Mac、Windows 和 Linux 的桌面应用
  • 全部 696 项检查,每项都附来源
  • Search Console 和 Analytics 4,以只读方式连接
  • 工单发送到 Jira、Linear 和 Asana

下载 Neova Desktop Free 套餐,或免费试用 Solo 14 天,无需银行卡。

全部可索引性检查 · 指南 · 检查项库

作者:Neova Labs · 返回检查项库