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).

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

CSS selectors by child or sibling rank

CSS. Selectors

Selector types
Simple selectors
Combinators
Selector list
Nesting syntax
Special selector
Misc