Definition and Usage
The [attribute="value"] selector selects all elements that have a specified attribute whose value exactly matches the specified value.
For example, the [target="_blank"] selector selects all elements in the document whose target attribute has a value that exactly matches _blank.
The [attribute="value"] selector matches any element that has the attribute attribute with a value of value.
Basic Example
[target="_blank"] { /* Selects all elements with a target attribute equal to "_blank". */
background-color: darkblue;
color: white;
}
<a href="https://www.example.com" title="Go to the official website">Visit Official Website</a>
<p>Learn <abbr title="Hypertext Markup Language">HTML</abbr> in a simple and fun way!</p>
<a target="_blank" href="https://www.example.com">Visit Example Website (Opens in a new tab)</a>
Syntax
The following two syntaxes are equivalent.
[attribute="value"][attribute='value']
[target="_blank"] {
background-color: darkblue;
color: white;
}
/* The following is also equivalent. */
[target='_blank'] {
background-color: darkblue;
color: white;
}
Browser Compatibility
| Selector |
Desktop Chrome
|
Desktop Edge
|
Desktop Firefox
|
Safari
|
|---|---|---|---|---|
[attribute="value"]
|
1 | 12 | 1 | 3 |
Specifications
| Specification | |
|---|---|
[attribute="value"]
|
Selectors Level 4 #attribute-selectors |
References
See Also
- CSS [attribute] Selector – Select Elements by Attribute Name
- CSS [attribute*="value"] Selector – Select Elements Whose Attribute Value Contains a Substring
- CSS [attribute~="value"] Selector – Select Elements Whose Attribute Value Contains a Word
- CSS [attribute^="value"] Selector – Select Elements Whose Attribute Value Starts With a Specific Value
- CSS [attribute$="value"] Selector – Select Elements Whose Attribute Value Ends With a Specific Value
- CSS ID Selector (#id) – Select Elements by ID Value
- CSS * Selector – Selects All Elements
- CSS Element Selector – Select by Element Name
- HTML Attribute Reference