HTML4 says to ignore empty P elements

Analyses and interpretation

Written 2000.03.18

HTML4.0 states User agents should ignore empty P elements.

This can be interpreted in at least two ways.

  1. User agents throw out empty P elements while parsing.
  2. User agents keep empty P elements as part of the parse tree, but render empty P elements as "display:none" by default.

The basic question is whether or not empty P elements are considered part of the parse tree.

If they are not part of the tree, that has all sorts of nasty implications for various CSS selectors such as :first-child, adjacency and especially some of the new CSS3 selectors.

However, there is nothing in DOM 1.0 HTML which says anything about empty P elements not being in the tree. Since there is nothing to indicate treatment otherwise, I believe empty P elements are accessible through the DOM, much as HTML comments are.

My understanding is that, in addition, legacy behavior parses empty P tags and considers them as part of the parse tree (and thus accessible through DOM etc.)

This behavior is more consistent with the second interpretation.

And that is my preference too, but I wanted to know if there was some other thinking behind what "ignore" means. So I consulted one of the editors of the HTML4 recommendation who remembers the history behind the decisions regarding the intent behind that statement.

His opinion as well was The 2nd choice. In particular, that empty p's shouldn't insert vertical whitespace.

Conclusion: empty P elements should be parsed, yet given an initial value of "none" for their CSS "display" property. Unfortunately there is no CSS-2 selector to select empty P elements, so this rendering behavior is currently beyond what CSS can specify. That should not be a problem however, as there are other HTML4 rendering behaviors which cannot be specified using CSS-2, so this interpretation does not make this particular problem any worse.

Outstanding questions: Do CSS-3 selectors support this? I thought there was some sort of :content pseudo-class, but I'm not sure if this selector can actually select emptiness. Did we forget zero?