Comment by vbezhenar
21 hours ago
Closing optional HTML tags just adds more ambiguity. How many HTMLParagraphElements here, what do you think?
<p>
text1
<p>
text2
</p>
</p>
21 hours ago
Closing optional HTML tags just adds more ambiguity. How many HTMLParagraphElements here, what do you think?
<p>
text1
<p>
text2
</p>
</p>
2. And there’s no ambiguity there, just invalid HTML because paragraphs aren’t nestable.
It may look nested but the first p is actually closed when the second p starts, according to https://developer.mozilla.org/en-US/docs/Web/HTML/Reference/...
Wouldn't this still result in just two paragraph elements? Yes, the first gets auto-closed, but I don't see how a third paragraph could emerge out of this. Surely that closing tag should just get discarded as invalid.
edit: Indeed, it creates three: the </p> seems to create an empty paragraph tag. Not the first time I've been surprised by tag soup rules.
Hence why I said “2” ;)
1 reply →
Browser will parse that as three HTMLParagraphElements. You may think that's invalid HTML, but browser will parse it and won't indicate any kind of error.
> Browser will parse that as three HTMLParagraphElements
Why?
> You may think that's invalid HTML, but browser will parse it and won't indicate any kind of error.
It isn’t an opinion, it literally is invalid HTML.
What you’re responding to is an assumption that I was suggesting browsers couldn’t render that. Which isn’t what I claimed at all. I know full well that browsers will gracefully handle incorrect HTML, but that doesn’t mean that the source is magically compliant with the HTML specification.
6 replies →
At the end of the day, browsers have to handle most of the invalid atrocities thrown at it.
It doesn't make the code valid according to the specifications.
3 replies →
Excellent catch
Why would you nest paragraph tags?
They are not nested, according to HTML5 parsing rules. You get 3 (yes, three) sibling paragraphs, including an empty one.
There being nesting is just implied by the closing tags and indentation. But it is not actually there. I think this is the point of the example: Adding the closing tags just confuses the reader, by implying nesting that is not actually there, and even introduces a third empty paragraph. It might be better left out entirely.
That is invalid syntax. Only phrasing content is allowed the p element (https://developer.mozilla.org/en-US/docs/Web/HTML/Guides/Con...)
The second <p> is not inside of the first. The first <p> closes when the second <p> is encountered.
The syntax is invalid, but that's because the final </p> has no opening <p> that it can close.
This is invalid html, p tag can be nested in a p tag.
Even though it arguably should be, according to HTML5 parsing rules, this is not invalid. It is just interpreted differently from what most people would probably expect.
I think this is the point of the example, afaiui: The closing tags don’t clarify anything, quite the contrary, actually. They serve only to confuse the reader.