Most Likely Cause and Fix
Your markup includes a
<p>
element inside a <h2>
and that this is not allowed.
Re-organise your markup so that this is not the case.
You may have an unclosed <p>
element further up
the page that is confusing the validator. Check this also.
What This Error Means
HTML is often comprised of elements nested inside other elements, such as the placing of an anchor within a paragraph:
<p> Hello <a href="http://example.com">World!</a> </p>
There are rules regarding which elements can be nested inside other elements and when this is allowed to happen.
Most notably, block-level elements, such as <div>
,
are not allowed inside inline elements such as <span>
.
This error is telling you that your markup includes a
<p>
element inside a <h2>
and that this is not allowed.
How To Fix It
If the error makes immediate sense
If you look at the line and column number given in the specific error
you encountered and you can see that you clearly have
a <p>
element inside a <h2>
,
you need to re-organise your markup so that this is not the case.
This can be a non-trivial task but here is some general advice:
-
don't use block-level elements inside inline elements
-
some elements can contain only a small set of child elements, such as lists (
<ol>
and<ul>
) allowing only list items (<li>
) as direct children
If the error does not make immediate sense
Check again. And then check again one more time.
The HTML validator can get confused. There's only so much sense it can try to derive from invalid markup.
If there really is not a
<p>
element inside a <h2>
in your markup at the point indicated by the line and column number in the
specific message you encountered, you will probably find that
there is an unclosed <p>
element further up
the page that is causing confusion.