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:
<!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
filter_none
Output:

Example 2:
<!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
filter_none
Output:

Recommended Posts:
- CSS | ::after Selector
- CSS | * Selector
- CSS | #id Selector
- CSS | :not Selector
- CSS | ::before selector
- CSS | Class Selector
- CSS | optional Selector
- jQuery | :even Selector
- CSS | :indeterminate Selector
- CSS | ::first-line Selector
- CSS | ::first-letter Selector
- jQuery | :gt() Selector
- CSS | :last-of-type Selector
- CSS | :target Selector
- CSS | :first-of-type Selector
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.



