CSS3 [attribute^=value] Selector

Definition and Usage

CSS [attribute^=value] The selector is used to match each element with an attribute value that starts with the specified value.

Example

Example 1

Set the background color for all <div> elements with a class attribute value that starts with "test":

div[class^="test"] {
  background: salmon;
}

Try it yourself

Example 2

Set the background color for all elements with a class attribute value that starts with "test":

[class^="test"] {
  background: salmon;
}

Try it yourself

CSS Syntax

[attribute ^= value] {
  css declarations;
}

Technical Details

Version: CSS3

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 3.5 3.2 9.6

Related pages

CSS Tutorial:CSS attribute selector

CSS Tutorial:Detailed Explanation of CSS Attribute Selectors