Skip to content

Report more-helpful message for *No p element in scope but a p end tag seen*  #103

Description

@evanorsouw

When checking the site whitemagic.it the following error is reported;

Error: No p element in scope but a p end tag seen.
From line 117, column 17; to line 117, column 20

↩

It appears this is an invalid error.

Activity

  1. sideshowbarker commented on Mar 28, 2017

    @sideshowbarker
    Member

    Please post the source of a document or document fragment that causes this error to be emitted

    Mostly likely this is reported because the document has something like this:

    <p>
      <ul>
      …
      </ul>
    </p>
    

    In that case what that document really looks like, as seen by an HTML parser, is this:

    <p></p>
      <ul>
      …
      </ul>
    </p>
    

    That’s because, the way HTML works is, a <ul> start tag implies a </p> close tag for any open p elements.

  2. cvrebert commented on Mar 28, 2017

    @cvrebert

    I feel like a FAQ for "p was implicitly closed by open tag of element disallowed by p's content model, thus making the explicit p close tag unmatched" is merited at this point. It seems to come up frequently on the issue tracker. Maybe with a link to other linter(s) that give more comprehensible error messages in that case.

  3. evanorsouw commented on Mar 28, 2017

    @evanorsouw
    Author

    Chris, you hit the spot right on. <p><ul></ul></p> is exactly what the html looks like.
    I guess there is a lot of html legacy at play, so I am fine with your explanation.
    Your suggestion to somehow improve the error message seems valid to prevent wasting time in the future as much as possible.
    Thx for the swift response.

  4. cvrebert commented on Mar 28, 2017

    @cvrebert

    Erm, Michael was the one who diagnosed your problem.

  5. evanorsouw commented on Mar 28, 2017

    @evanorsouw
    Author

    ah yeah, my bad, thanks michael.

  6. changed the title [-]Invalidly reporting mismatching element[/-] [+]Report more-helpful message for *No p element in scope but a p end tag seen* [/+] on Mar 31, 2017
  7. kdlogen commented on Apr 11, 2025

    @kdlogen

    Hi there! I also encountered an error during validation related to the

    element. I received the same error with the following structure:

    <!DOCTYPE html>
    <html lang="">
    <head>
      <title>abc</title>
    </head>
    <body>
      <p>
        <p>
        </p>
      </p>
    </body>
    </html>

    I used this validator to test the content: https://validator.w3.org/nu/#textarea

    I also tested the resulting DOM structure in Firefox, Safari, and Chrome. In all cases, the browsers automatically inserted missing start/end tags, modifying the structure. Additionally, Firefox showed an error for the last </p> tag in "View source" mode.

    Results in browsers
    <!DOCTYPE html>
    <html lang="">
    <head>
      <title>abc</title>
    </head>
    <body>
      <p></p>
        <p></p>
      <p></p>
    </body>
    </html>

    According to the p element documentation, when a new <p> tag appears inside an open <p>, the first one is automatically closed. This automatic closing causes the second </p> to generate an error during validation.

    I wanted to share this here in case it helps someone else encountering the same issue.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or request

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions