CSS [attribute|=value] Selector
- Previous page [attribute~=value]
- Next Page [attribute^=value]
- Go to the Previous Level CSS Selector Reference Manual
Definition and Usage
CSS [attribute|=value]
The selector is used to select elements that have a specified attribute and whose attribute value matches exactly or starts with the specified value followed by a hyphen (−).
Note:The value must be a complete word, either appearing alone, such as lang="en", or followed by a hyphen (−), such as lang="en-us".
Example
Example 1
Select and set the style of elements with lang attribute value of "en" or "en-":
[lang|="en"] { background-color: yellow; }
Example 2
Select and set the style of elements with class attribute value of "top" or "top-":
[class|="top"] { background-color: yellow; }
CSS Syntax
[attribute |= value] { 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
- Previous page [attribute~=value]
- Next Page [attribute^=value]
- Go to the Previous Level CSS Selector Reference Manual