Private archive copy · Unofficial site · Content copyright belongs to Runoob Tutorial and the original authors · View Original

CSS [attribute|=value] selector

CSS [attribute|=value] selector

Complete CSS SelectorComplete CSS Selector Reference Manual

Example

Select all elements whose lang attribute equals en or begins with en-, and set their style:

[

lang

|=

en

]

{

background-color:

yellow

;

}

Try it »


Definition and Usage

[attribute|=valueThe ] selector is used to select elements whose attribute value begins with a specified value.

**Note:** The value must be a whole word, either alone such as lang="en", or followed by a hyphen - as in lang=en-us is acceptable.


Browser support

Internet ExplorerFirefoxOperaGoogle ChromeSafari

All major browsers support [attribute|=value] selector.

Note: [attribute|=value] must have a DOCTYPE declared to work in IE8


Related Articles

CSS Tutorial: CSS attribute selectors


More examples

Example

Select all elements whose class attribute begins with top and set them to yellow:

[

class

|=

top

]

{

background-color:

yellow

;

}

Try it »


Complete CSS SelectorComplete CSS Selector Reference Manual