Skip to main content
Validación HTML

Non-space character after body.

Acerca de este problema HTML

The HTML specification defines a strict structure for documents: the <html> element contains a <head> and a <body>, and all visible page content must live inside the <body>. Once the browser encounters the </body> closing tag, it expects nothing but optional whitespace (spaces, tabs, newlines) before the closing </html> tag. Any non-space characters in that gap — whether text, HTML elements, script tags, or even stray punctuation — are considered outside the document body and trigger this validation error.

Why this matters

  • Standards compliance: The HTML living standard (WHATWG) is clear that content after </body> is not valid. W3C validation will flag this as an error.
  • Unpredictable rendering: Browsers use error recovery to handle misplaced content, and different browsers may handle it differently. Most will implicitly reopen the <body> and move the content inside it, but relying on this behavior is fragile and unpredictable.
  • Accessibility: Screen readers and assistive technologies parse the DOM structure. Content that lands in unexpected places due to error recovery may be announced out of order or missed entirely.
  • Maintainability: Stray content after </body> is often a sign of a code organization problem — a misplaced include, a template rendering issue, or an accidental paste — and cleaning it up improves long-term maintainability.

Common causes

  1. Accidental text or typos after the closing </body> tag.
  2. Script or analytics tags mistakenly placed between </body> and </html> instead of at the end of the <body>.
  3. Server-side template engines appending content after the body in a layout file.
  4. Comments or debugging output left behind after </body>.

Examples

Stray text after </body>

This triggers the validation error because the text this is invalid appears after </body>:

<!DOCTYPE html>
<html lang="en">
  <head>
    <title>Example</title>
  </head>
  <body>
    <p>Content goes here.</p>
  </body> this is invalid
</html>

Move all content inside the <body>:

<!DOCTYPE html>
<html lang="en">
  <head>
    <title>Example</title>
  </head>
  <body>
    <p>Content goes here.</p>
  </body>
</html>

Script placed outside the body

A common mistake is placing a <script> tag between </body> and </html>:

<!DOCTYPE html>
<html lang="en">
  <head>
    <title>Example</title>
  </head>
  <body>
    <p>Main content</p>
  </body>
  <script src="analytics.js"></script>
</html>

Place the script at the end of the <body> instead:

<!DOCTYPE html>
<html lang="en">
  <head>
    <title>Example</title>
  </head>
  <body>
    <p>Main content</p>
    <script src="analytics.js"></script>
  </body>
</html>

Stray HTML element after </body>

Sometimes an element like a <div> ends up after the body due to a template issue:

<!DOCTYPE html>
<html lang="en">
  <head>
    <title>Example</title>
  </head>
  <body>
    <main>Page content</main>
  </body>
  <div id="overlay"></div>
</html>

Move it inside <body>:

<!DOCTYPE html>
<html lang="en">
  <head>
    <title>Example</title>
  </head>
  <body>
    <main>Page content</main>
    <div id="overlay"></div>
  </body>
</html>

The fix is always the same: ensure that everything between </body> and </html> is either whitespace or nothing at all. All content — text, elements, scripts, and comments — belongs inside the <body> element.

Encuentra problemas como este automáticamente

Rocket Validator escanea miles de páginas en segundos, detectando problemas de HTML en todo tu sitio web.

Ayúdanos a mejorar nuestras guías

¿Te ha sido útil esta guía?

¿Listo para validar tus sitios?
Inicia tu prueba gratuita hoy.