W3.org states:
We discourage authors from using empty P elements.
User agents should ignore empty P elements.
How do we define empty?
Does a space character between the <p> </p>
tags count?
What about a new-line character between <p> </p>
?
The HTML4 spec defines an empty element as one that has no content. Self-closing tags definitely define empty elements, like <br/>
and <img/>
. I think it's very reasonable to expect that a start tag immediately followed by an end tag, such as <p></p>
also defines an empty element. Whether or not <p> </p>
qualifies as "empty" is likely up to the user agent, but let's look at the inline content model definition from the spec:
<!-- %inline; covers inline or "text-level" elements -->
<!ENTITY % inline "#PCDATA | %fontstyle; | %phrase; | %special; | %formctrl;">
"Empty" content is one that contains none of the following:
#PCDATA
%fontstyle;
%phrase;
%special;
%formctrl;
So is a space character any of the above? Yes, it's #PCDATA
, so I would deduce that <p> </p>
is not an empty P
element. And regardless of the HTML4 spec's discouragement, <p></p>
, <p> </p>
, and <p/>
are all a perfectly valid HTML fragments.
Such elements are now called "void" by the HTML5 spec.
@Alohci clarifies:
The term "void elements" in HTML5 refers to those element types whose instances can never have content like br and img, not to instances that happen to have no content. So instances of P elements never constitute a "void element."
The HTML5 spec makes no such comment about avoiding "empty" or "void" P
elements:
...I really wouldn't worry too much about it.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With