CSS [attribute] Selector

Definition and Usage

CSS [attribute] The selector is used to select elements with specified attributes.

Example

Select and set the styles of all <a> elements with the target attribute. At the same time, select and set the styles of all <p> elements with the lang attribute:

a[target] {
  background-color: yellow;
}
p[lang] {
  background-color: salmon;
}

Try It Yourself

CSS Syntax

[attribute] {
  css declarations;
}

Technical Details

Version: CSS2

Browser Support

The numbers in the table indicate the first browser version that fully supports this selector.

Chrome Edge Firefox Safari Opera
4.0 7.0 2.0 3.1 9.6

Related Pages

CSS Tutorial:CSS attribute selector

CSS Tutorial:Detailed Explanation of CSS Attribute Selectors