Tutorialspoint.dev

CSS | :empty Selector

The :empty selector is used to select that element which does not contain any children (including text node).

Syntax:

:empty {
    // CSS property
} 

Example:

<!DOCTYPE html>
<html>
    <head>
        <title>empty selector</title>
        <style
            h1 {
                color:green;
            }
            div:empty {
                width: 150px;
                height: 20px;
                background: green;
            }
        </style>
    </head>
    <body>
        <center>
            <h1>GeeksforGeeks</h1>
            <h2>:empty selector</h2>
            <div></div><br>
            <div>A computer science portal for geeks</div>
        </center>
    </body>
</html>                    

Output:

Supported Browsers: The browser supported by :empty selector are listed below:

  • Apple Safari 3.2
  • Google Chrome 4.0
  • Firefox 3.5
  • Opera 9.6
  • Internet Explorer 9.0


This article is attributed to GeeksforGeeks.org

leave a comment

code

0 Comments

load comments

Subscribe to Our Newsletter