CSS: no child selector

By Xah Lee. Date: . Last updated: .
tag:empty

Match tag that has no children.

🛑 warning: inner-text count as children, including just whitespace.

tag is optional. It can be a simple selector (selecting by tag name, id, class etc) or a compound selector (combination of tag name, id, class etc). If empty, it means the universal selector (* any tag).

<div></div>
p:empty {
 background-color: orange;
 width: 50px;
 height: 50px;
}