3 ms·
It's only because there's a known structure for HTML. A block-level element cannot be within another block, but you have to know that "p" and "ul" are block-lev
by Mikhail_Edoshin 6y ago
It's only because there's a known structure for HTML. A block-level element cannot be within another block, but you have to know that "p" and "ul" are block-level. Explicit closing does not require you to know the structure and thus makes the processing simpler.
It's as in JavaScript: you can omit the ";" at the end of a statement and the parser will figure it out, but it only makes the parser more complex and introduces subtle differences you have to learn. If JS parser were more strict, it would be simpler both internally and conceptually.
- wayvey 6y agoThe second sentence is wrong: there's nothing wrong with nested block elements, but you never nest block elements inside inline elements. For example <div> elements are block-level and they are nested all the time. There are some exceptions though such as your example of an <ul> in a <p>. The <p> tag only permits "phrasing content" within itself, and <ul> isn't considered phrasing content. MDN definition of phrasing content: https://developer.mozilla.org/en-US/docs/Web/Guide/HTML/Content_categories#Phrasing_content https://developer.mozilla.org/en-US/docs/Web/Guide/HTML/Cont...
- Mikhail_Edoshin 6y agoThanks for the correction (I don't really know the HTML flow model and was guessing it.)