HTML Guides for unclosed elements
Learn how to identify and fix common HTML validation errors flagged by the W3C Validator — so your pages are standards-compliant and render correctly across every browser. Also check our Accessibility Guides.
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>:
<!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>:
<!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:
<!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>
Validate at scale.
Ship accessible websites, faster.
Automated HTML & accessibility validation for large sites. Check thousands of pages against WCAG guidelines and W3C standards in minutes, not days.
1K Weekly
1,000 monthly checks. Cancel anytime.
Get 1K Weekly →Join teams across 40+ countries