# End tag for “html” seen, but there were unclosed elements.

> Canonical HTML version: https://rocketvalidator.com/html-validation/end-tag-for-html-seen-but-there-were-unclosed-elements
> Attribution: Rocket Validator (https://rocketvalidator.com)
> License: CC BY 4.0 (https://creativecommons.org/licenses/by/4.0/)

The parser reached the `</html>` end tag while one or more elements in the document, such as a `<div>` or a `<main>`, were still open.

The `</html>` end tag closes the whole document, so every element started inside it has to be closed first. When the parser gets to `</html>` and finds open elements, it closes them all at that point. The validator reports this error and adds an "Unclosed element" message for each element it had to close, which tells you which tags are missing.

The most common cause is a forgotten closing tag near the end of the page, often in a template that also leaves out `</body>`. Add the missing end tags in reverse order of the start tags, then close `</body>` before `</html>`.

A second cause is a complete HTML document pasted into the body, usually an embed code or a fragment from a CMS that brings its own `<!DOCTYPE html>`, `<html>` and `</html>`. The inner `</html>` ends the document early, while the elements around the embed are still open. The validator then also reports "Stray doctype", "Stray start tag “html”" and a stray end tag for the elements that come after it. Remove the inner doctype and `<html>` tags and keep only the content between them.

## Invalid example

The `<div>` is never closed, and the page has no `</body>`:

```html
<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="utf-8">
    <title>Example</title>
  </head>
  <body>
    <div class="content">
      <p>Hello, world!</p>
</html>
```

An embedded document inside the body ends the outer document at its own `</html>`:

```html
<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="utf-8">
    <title>Example</title>
  </head>
  <body>
    <main>
      <div class="widget">
        <!DOCTYPE html>
        <html>
          <p>Embedded content</p>
        </html>
      </div>
    </main>
  </body>
</html>
```

## Valid example

Close every element before `</body>` and `</html>`, and keep only the content of any embedded document:

```html
<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="utf-8">
    <title>Example</title>
  </head>
  <body>
    <main>
      <div class="widget">
        <p>Embedded content</p>
      </div>
    </main>
  </body>
</html>
```
