pseudo-class
:empty — CSS reference
Tests emptiness. Comments do not count; current Chromium behavior treats even whitespace text as content. Selectors Level 4 proposes allowing document whitespace, so do not rely on whitespace-only matching across implementations.
Formal Syntax & Structure
css syntaxcss
:emptyWorking Example
Example Snippetcss
<!doctype html><html lang="en"><head><meta charset="utf-8"><title>Selector lab</title><style>:where(.sample) { color: rgb(32, 32, 32); }p:empty { color: rgb(0, 96, 80); }</style></head><body><p id="a" class="sample"><!-- note --></p><p id="b" class="sample"> </p></body></html>