logoalt Hacker News

dylan604today at 2:35 PM2 repliesview on HN

Is HTML that way because of it being HTML, or have browsers just decided to brute force their way into handling the slop so that people won't blame the browser for not doing it correctly?


Replies

alt227today at 2:40 PM

In my experience a lot of the "best practice" warnings are reductive.

A couple examples from this list are not requiring a type parameter on certain tags, or style tags being valid under html and body tags but not div tags. These types of things would take extra coding in a browser to check for certain singular tags not requiring things that all others do. Therefore it is simpler to leave these checks out and leave sloppy syntax checking as it does no harm at all to the rendered markup.

You may be right in some situations, but the nature of HTML having everything applied to all tags and then selectively reduced definitely helps make it a more resilient and accommodating language.

show 1 reply
ndiddytoday at 2:57 PM

Well it's obviously a better experience for someone who's not the page author if the browser tries to render an invalid page rather than throwing up its hands and showing an error. That way you can at least try to read the page rather than not being able to and having to track down the author and try to get him to fix his site. The "strict parsing" fans tried to force correctness with XHTML, but it was a failure and didn't see much use.

The main problem with "handling the slop" used to be that different browsers would render invalid HTML differently, so poorly written sites could look very different depending on the browser you used. Modern HTML standardizes how browsers handle invalid HTML so this isn't a problem anymore. See https://html.spec.whatwg.org/multipage/parsing.html