CSS empty Selector (:empty)

What is CSS :empty Selector?

CSS :empty selector select all element whose haven't any children element even not any text node.

Syntax

General syntax of CSS :empty selector,

:empty {
  property: value;
  property: value;
  ...
}

div:empty {
  property: value;
  property: value;
  ...
}

Example

CSS :empty selector select all element whose haven't any children element or not any next node.

<!DOCTYPE html>
<html>
<head>
  <title>CSS :empty Selector</title>
  <style type="text/css">
    div:empty {
      width:100px;
      height:20px;
      background:#ff0000;
    }
  </style>
</head>
<body>
  <div></div>
  <div>first paragraph.</div>
  <div>Another one paragraph.</div>
</body>
</html>

Run it...   »

Browser Compatibility

  • Google Chrome 2+
  • Mozilla Firefox 1.5+
  • Internet Explorer 9+
  • Opera 9.5+
  • Safari 3.1+

Note: Here details of browser compatibility with version number may be this is bug and not supported. But recommended to always use latest Web browser.