CSS [attribute=value] Selector
Example
Select and style all <a> elements with target="_blank". Also select and style all <p> elements with lang="it":
a[target="_blank"] {
background-color: yellow;
}
p[lang="it"]
{
background-color: salmon;
}
Try it Yourself »
More "Try it Yourself" examples below.
Definition and Usage
The [attribute=value]
selector is used to select elements with the specified attribute and
the exact value.
Version: | CSS2 |
---|
Browser Support
The numbers in the table specifies the first browser version that fully supports the selector.
Selector | |||||
---|---|---|---|---|---|
[attribute=value] | 4.0 | 7.0 | 2.0 | 3.1 | 9.6 |
CSS Syntax
More Examples
Example
Set the width of an <input type="text"> element to 100px. However, when it gets focus, make it 250px wide:
input[type="text"] {
width: 100px;
}
input[type="text"]:focus {
width: 250px;
}
Try it Yourself »
Related Pages
CSS tutorial: CSS Attribute Selectors