About This HTML Issue
When the W3C HTML Validator reports “No X element in scope but a X end tag seen,” it means the parser encountered a closing tag for an element that was never opened, or that was already closed. The validator tracks which elements are currently “in scope” — meaning which opening tags are still waiting for their corresponding closing tags. When a closing tag appears that doesn’t match any open element in scope, this error is raised.
This issue matters for several reasons. First, it indicates malformed HTML that browsers must guess how to interpret, potentially leading to inconsistent rendering across different browsers. Second, broken document structure can confuse assistive technologies like screen readers, harming accessibility. Third, stray end tags can inadvertently affect the DOM tree in unexpected ways, making your CSS and JavaScript behave unpredictably.
There are several common causes:
- Closing a tag twice — the most frequent cause, where a copy-paste error or oversight leads to a duplicate closing tag.
- Missing the opening tag — the corresponding opening tag was accidentally deleted or never added.
- Misnested tags — elements overlap instead of being properly nested, causing the browser to auto-close one element, which makes a later closing tag orphaned.
-
Typos in tag names — an opening tag has a different name than the closing tag (e.g.,
<div>opened but</dvi>used to close it, though this usually triggers a different error).
To fix this, carefully review the HTML around the flagged line. Trace each closing tag back to its opening tag. Using a code editor with bracket/tag matching can make this much easier. Remove any duplicate end tags, add any missing opening tags, or fix nesting order as needed.
Examples
Closing a tag twice
This is the most common cause. The </p> tag appears twice:
<!-- ❌ Bad: duplicate closing tag -->
<p>Hello world</p></p>
Remove the extra closing tag:
<!-- ✅ Good -->
<p>Hello world</p>
Missing opening tag
Here a </span> end tag has no corresponding <span>:
<!-- ❌ Bad: no opening <span> -->
<div>
Some text</span>
</div>
Either add the missing opening tag or remove the stray end tag:
<!-- ✅ Good: opening tag added -->
<div>
<span>Some text</span>
</div>
Misnested tags
When elements overlap instead of nesting properly, the browser auto-closes the inner element, leaving a later closing tag orphaned:
<!-- ❌ Bad: <b> and <i> overlap -->
<p><b>Bold and <i>italic</b> text</i></p>
In this case, the browser closes the <i> when it encounters </b> (since <i> is inside <b>), so the later </i> has no element in scope. Fix it by nesting correctly:
<!-- ✅ Good: proper nesting -->
<p><b>Bold and <i>italic</i></b> <i>text</i></p>
Stray end tag after auto-closed element
Some elements like <p> are automatically closed by certain subsequent tags. This can lead to orphaned end tags:
<!-- ❌ Bad: <p> is auto-closed by <div>, leaving </p> orphaned -->
<p>Some text
<div>A block element</div>
</p>
The <p> element cannot contain a <div>, so the browser implicitly closes the <p> before the <div>. The final </p> then has no <p> in scope. Restructure the markup:
<!-- ✅ Good: separate elements -->
<p>Some text</p>
<div>A block element</div>
Tip: use editor tooling
Most modern code editors can highlight matching opening and closing tags. If you see a closing tag without a highlighted match, that’s likely the source of this error. Extensions for VS Code, Sublime Text, and other editors can also auto-format and validate your HTML as you type, catching these issues early.
Find issues like this automatically
Rocket Validator scans thousands of pages in seconds, detecting HTML issues across your entire site.