CSS | [attribute=value] Selector

The [attribute=value] selector in CSS is used to select those element whose attribute value is equal to “value”.

Syntax:

element [attribute = "value"] {
    // CSS Property
}

Note: <!DOCTYPE> must be declared for IE8 and earlier versions.

Example 1:

filter_none

edit
close

play_arrow

link
brightness_4
code

<!DOCTYPE html>
<html>
    <head>
          
        <!-- CSS property used here -->
        <style>
            h1[id = "geeks"] {
                background-color: green;
                color:white;
            }
            li[class = "gfg"] {
                color:green;
            }
        </style>
    </head>
      
    <body>
        <h1 id = "geeks">GeeksforGeeks</h1>
        <ul>
            <li class = "gfg">Data Structure</li>
            <li class = "geeks">Algorithm</li>
            <li class = "gfg">DBMS</li>
            <li class = "geeks">C++ programming</li>
        </ul>
  
    </body>
</html>                    

chevron_right


Output:
Image

Example 2:

filter_none

edit
close

play_arrow

link
brightness_4
code

<!DOCTYPE html>
<html>
    <head>
        <title>
            CSS [attribute=value] Selector
        </title>
          
        <!-- CSS property -->
        <style>
            p[this=Geeks] {
                background-color: green;
                color:white;
            }
        </style>
    </head>
      
    <body>
        <h2>[attribute=value] Selector</h2>
        <p this = "Geeks">Paragraph 1</p>
        <p this = "geeks">Paragraph 2</p>
        <p this="Geeks">Paragraph 2</p>
    </body>
</html>                    

chevron_right


Output:
Image



My Personal Notes arrow_drop_up

Image
Check out this Author's contributed articles.

If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to contribute@geeksforgeeks.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.

Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.