O'Reilly logo

CSS Pocket Reference, 4th Edition by Eric A. Meyer

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Name

:empty

Applies to:

Any element

Description:

Matches elements that have no child nodes; that is, no child elements or content nodes. Content nodes are defined as any text, whitespace, entity reference, or CDATA nodes. Thus, <p> </p> is not empty; nor is the element empty if the space is replaced with a newline. Note that this pseudo-class does not apply to empty elements such as br, img, input, and so on.

Examples:

p:empty {padding: 1em; background: red;}
li:empty {display: none;}

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required