Role of CSS :empty Selector

Use the CSS :empty selector to style every <p> element that has no children with CSS. You can try to run the following code to implement the :empty selector −


Live Demo

<!DOCTYPE html>
         p.demo {
            width: 300px;
            height: 20px;
            background: gray;
          p:empty {
             width: 150px;
             height: 20px;
             background: orange;
      <p class = "demo">This is demo text. Below is empty text.</p>