CSS [attribute]
selector selects all the elements that have a given attribute. For example, it can select all the <img>
elements that have an alt
attribute or select all the <a>
elements that have a target
attribute regardless of the value of the attribute.
In the example below, the [attribute] selector selects all the <a>
elements that have a target
attribute and sets their background color to yellow. Try it out:
Example:
a[target]{ background: yellow; }
Selects all the <img>
elements that have an alt
attribute and set their border-radius to 50%.
Example:
img[alt]{ border-radius: 50%; }
CSS Syntax
The [attribute] selector has the following syntax:
[attribute]{ CSS styles }
Related Pages
CSS Tutorials: CSS Attribute Selectors