← Back to context

Comment by hnlmorg

17 hours ago

> 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.

>Why?

Because the second open p-tag closes the first p-tag and then the last closing p has no matching starting p-tag and creates one thus resulting in 3 p-elements.

> It isn’t an opinion, it literally is invalid HTML.

the only "invalid" part is the last closing p.

> Why?

I don't know why. Try it out. That's the way browsers are coded.

> It isn’t an opinion, it literally is invalid HTML.

It matters not. You're writing HTML for browser to consume, not for validator to accept. And most of webpages are invalid HTML. This very HN page contains 412 errors and warnings according to W3C validator, so the whole point of HTML validness is moot.

  • > I don't know why. Try it out. That's the way browsers are coded.

    I’m not saying you’re wrong, but I’d need more than that to be convinced. Sorry.

    > It matters not. You're writing HTML for browser to consume, not for validator to accept.

    It matters because you’re arguing a strawman argument.

    We weren’t discussing what a browser can render. We were discussing the source code.

    So your comment wasn’t a rebuttal of mine. It was a related tangent or addition.

    • > I’m not saying you’re wrong, but I’d need more than that to be convinced. Sorry.

      So basically my point is:

      1. You can avoid closing some tags, letting browser to close tags for you. It won't do any harm.

      2. You can choose to explicitly close all tags. It won't do anything for valid HTML, but it'll introduce subtle and hard to find DOM bugs by adding empty elements.

      So you're trying to improve HTML source readability by risking to introduce subtle bugs.

      If you want to do that, I'd recommend to implement HTML validation for build or test pipeline at least.

      Another alternative is to use HTML comments to close tags, as this closing tag is supposed to be documentation-only and won't be used by browser in a proper code.

      1 reply →

  • > You're writing HTML for browser to consume, not for validator to accept.

    I'm not a web programmer, but shouldn't one program against the specified interface instead of some edge case behavior of an implementation?