Are empty divs bad?

From the HTML5 spec:

3.2.8.2.8 Palpable content

As a general rule, elements whose content model allows any flow content or phrasing content should have at least one child node that is palpable content and that does not have the hidden attribute specified.

This requirement is not a hard requirement, however, as there are many cases where an element can be empty legitimately, for example when it is used as a placeholder which will later be filled in by a script, or when the element is part of a template and would on most pages be filled in but on some pages is not relevant.

So since divs allow flow content. empty divs are something generally to be avoided, but not invalid nor anything to get hung up about.

Leave a Comment