attribute

Attribute Presence Selector

Selects elements that have the specified attribute set, regardless of its value. Useful for targeting elements based on the mere presence of an attribute.

[attr]

Example

a[target] { color: red; } /* HTML: <a href="#" target="_blank">Link</a> */

✓ Matches

  • <a target="_blank">Link</a>
  • <a target="">Link</a>
  • <a target="_self">Link</a>

✗ Does not match

  • <a href="#">Link</a>
  • <a>Link</a>

Browser support

Universal support in all browsers since CSS2.

Related selectors

← All CSS selectors · CSS selectors cheat sheet