CSS: no child selector

By Xah Lee. Date: . Last updated: .

check if no children

tag:empty

Match tag that has no children.

tag here is compound selector, or none, which means the universal selector (* any tag).

πŸ›‘ WARNING: inner-text count as children, including just whitespace.

p:empty {
 background-color: yellow;
 width: 50px;
 height: 50px;
}

CSS, Selectors

Selector types
Simple selectors
Combinators
Selector list
Special selector
Misc