Skip to main content
HTML Validation

Saw an end tag after “body” had been closed.

About This HTML Issue

Every valid HTML document follows a strict structure: a <!DOCTYPE html> declaration, followed by an <html> element containing exactly two children — <head> and <body>. All visible content and its associated markup must live inside <body>. Once the browser encounters the </body> closing tag, it expects nothing else except the closing </html> tag.

When an end tag appears after </body> has been closed, the browser’s parser enters an error-recovery mode. While most browsers will attempt to handle this gracefully, the behavior is not guaranteed to be consistent. This can lead to unexpected DOM structures, which may cause issues with JavaScript that relies on the DOM tree, break CSS styling, or create accessibility problems for screen readers that depend on proper document structure.

This issue commonly arises from:

  • Extra or duplicate closing tags — for example, an extra </div> that doesn’t match any open element inside <body>.
  • Accidentally placing elements after </body> — such as moving a <script> or </div> outside the body during editing.
  • Copy-paste errors — fragments of markup pasted in the wrong location.
  • Template or CMS issues — server-side templates that inject closing tags in the wrong order.

To fix this, review your document structure carefully. Make sure every opening tag inside <body> has a matching closing tag also inside <body>. Ensure nothing appears between </body> and </html> except whitespace.

Examples

Incorrect — end tag after body is closed

<!DOCTYPE html>
<html lang="en">
  <head>
    <title>My Page</title>
  </head>
  <body>
    <div>
      <p>Hello world</p>
    </div>
  </body>
  </div>
</html>

Here, an extra </div> sits between </body> and </html>. This triggers the validation error because the body has already been closed when the parser encounters </div>.

Incorrect — script tag placed after body

<!DOCTYPE html>
<html lang="en">
  <head>
    <title>My Page</title>
  </head>
  <body>
    <p>Hello world</p>
  </body>
  <script src="app.js"></script>
</html>

While browsers will typically still execute the script, placing it after </body> is invalid and produces this warning.

Correct — all content and tags inside body

<!DOCTYPE html>
<html lang="en">
  <head>
    <title>My Page</title>
  </head>
  <body>
    <div>
      <p>Hello world</p>
    </div>
    <script src="app.js"></script>
  </body>
</html>

All elements, including <script> tags, are properly nested inside the <body> element. The only thing that follows </body> is </html>.

Debugging tip

If your document is large and you’re having trouble finding the stray tag, try these approaches:

  1. Count your tags — make sure every opening tag (like <div>) has exactly one matching </div> inside <body>.
  2. Use an editor with bracket matching — most code editors can highlight matching open/close tags, making orphaned tags easy to spot.
  3. Check the validator’s line number — the W3C validator reports the line where the stray end tag was found, which points you directly to the problem.
  4. Indent properly — consistent indentation makes structural problems visually obvious.

Find issues like this automatically

Rocket Validator scans thousands of pages in seconds, detecting HTML issues across your entire site.

Help us improve our guides

Was this guide helpful?

Ready to validate your sites?
Start your free trial today.