Definition and Usage
The [attribute] selector selects all elements that have an attribute whose name matches the specified attribute.
For example, the [title] selector selects all elements in the document that have a title attribute.
The [attribute] selector matches any element that has the attribute attribute, regardless of its value.
Example - 1
[title] { /* Selects all elements that have a title attribute. */
background-color: darkblue;
color: white;
}
<p>Let's learn <abbr title="Hypertext Markup Language">HTML</abbr> in a simple and fun way!</p>
<a href="https://www.example.com" title="Visit the official website">Example Website</a>
Example - 2
[cite] { /* Selects all elements that have a cite attribute. */
background-color: yellowgreen;
}
<p>
Tim Berners-Lee said,
<q cite="https://example.com/example">
The Web is a human right.
</q>
</p>
Tim Berners-Lee said,
The Web is a human right.
Browser Compatibility
| Selector |
Desktop Chrome
|
Desktop Edge
|
Desktop Firefox
|
Safari
|
|---|---|---|---|---|
[attribute]
|
1 | 12 | 1 | 3 |
Specifications
| Specification | |
|---|---|
[attribute]
|
Selectors Level 4 #attribute-selectors |
References
See Also
- CSS [attribute="value"] Selector – Select Elements by Attribute Name and Value
- 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 * Selector – Selects All Elements
- CSS Element Selector – Select by Element Name
- HTML Attribute Reference