Hacker News new | past | comments | ask | show | jobs | submit login

That's only true in very specific cases: https://developer.mozilla.org/en/docs/Web/HTML/Element/p

The start tag is mandatory. The end tag may be omitted if the <p> element is immediately followed by an <address>, <article>, <aside>, <blockquote>, <div>, <dl>, <fieldset>, <footer>, <form>, <h1>, <h2>, <h3>, <h4>, <h5>, <h6>, <header>, <hr>, <menu>, <nav>, <ol>, <pre>, <section>, <table>, <ul> or another <p> element, or if there is no more content in the parent element and the parent element is not an <a> element.




And "there is no more content in the parent element" applies here.

Actually, what you call "very specific cases" are in fact, well, all reasonable cases. That list consists of all block level elements that can appear in `body`, so the statement could be reworded, that "<p> cannot contain any block-level element, so any inline element after <p> falls in, any block level element ends opened <p>".

Funny fact is that presence of optional end tags means nearly nothing for HTML parsers used in current browsers, they just ignore them. Some border cases regarding white space exists, or at least existed in the past, but in general, if you feed browser with document

    <!doctype html><html><head><title>a</title></head><body><table><tbody><tr><td><p>b</p></td></tr></tbody></table></body></html>`
or

    <!doctype html><title>a</title><table><tr><td><p>b</table>`
makes absolutely no difference. Both will result in exactly same DOM tree, both are "100% valid W3C HTML documents".




Consider applying for YC's W25 batch! Applications are open till Nov 12.

Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: