← Back to pseudo-classes

CSS Pseudo-class / Element

:empty

Structural

Selects elements that have no children, including no text nodes.

Syntax

selector:empty { }

Example

div:empty { display: none; }

Common use cases

  • Hiding empty containers automatically
  • Styling empty state placeholders
  • Removing spacing from empty elements

Practical developer insight

Even a single space counts as a text node — :empty won't match if there's whitespace inside the element. This catches many developers off guard.

Related