swc-project/swc · error · Error
SomethingBetweenHeadAndBody
SomethingBetweenHeadAndBody
Error message
"{tag_name}" element between "head" and "body" What it means
HTML parse error in the 'after head' insertion mode: a start tag for a head-only element (base, basefont, bgsound, link, meta, noframes, script, style, template, title) appeared after </head> but before <body>. Per spec it is reprocessed using the 'in head' rules while the error is recorded.
Source
Thrown at crates/swc_html_parser/src/parser/mod.rs:2225
//
// Remove the node pointed to by the head element pointer from the stack of open
// elements. (It might not be the current node at this point.)
Token::StartTag { tag_name, .. }
if matches!(
&**tag_name,
"base"
| "basefont"
| "bgsound"
| "link"
| "meta"
| "noframes"
| "script"
| "style"
| "template"
| "title"
) =>
{
self.errors.push(Error::new(
token_and_info.span,
ErrorKind::SomethingBetweenHeadAndBody(tag_name.clone()),
));
let head = self
.head_element_pointer
.as_ref()
.expect("no head element")
.clone();
self.open_elements_stack.push(head.clone());
self.process_token_using_rules(token_and_info, InsertionMode::InHead)?;
self.open_elements_stack.remove(&head);
}
// An end tag whose tag name is "template"
//
// Process the token using the rules for the "in head" insertion mode.
Token::EndTag { tag_name, .. } if tag_name == "template" => {View on GitHub (pinned to 5176682b65)
Solutions
- Move the element inside <head>
- Start the <body> before emitting body-level content
Defensive patterns
Strategy: validation
When it happens
Trigger: Thrown at crates/swc_html_parser/src/parser/mod.rs:2225 when the library encounters an invalid state.
Common situations: See trigger scenarios.
AI-assisted analysis of swc-project/swc@5176682b65 (2026-08-17).
Data as JSON: /api/errors/b4e20c569764b11a.
Report an issue: GitHub.