Attribute selectors match elements based on either the presence of an attribute, or the partial or exact match of an attribute value.
Attribute selectors match elements based on either the presence of an attribute, or the partial or exact match of an attribute value.
Strings, as distinct from identifiers (elements, id and class attributes) must be quoted in attribute selectors.
Action | Description | CSS Example |
---|---|---|
contains | Applies to elements that have an attribute which contains the specified value, for example, the title attribute contains 'copy', which will select 'copyright' and 'photocopy'. |
|
contains-word | Applies to elements that have an attribute which contains the specified word, for example, menu labels with a class containing 'sport' in a space-separated list of words. |
|
ends-with | Applies to elements that have an attribute which contains a value which ends with the specified value, for example, image with a src attribute ending in '.png'. |
|
equals | Applies to elements that have an attribute which is equal to the specified value, for example, a paragraph with the class attribute 'relinfo'. |
|
language-match | Applies to elements that have the lang attribute set to the specified language, for example, a paragraph with a lang attribute of 'fr' or beginning with 'fr' and immediately followed by '-'. |
|
set | Applies to elements that have the specified attribute set, for example, any list item with the title attribute set. |
|
starts-with | Applies to elements that have an attribute containing a value which starts with the specified value, for example, menuitem links to a 'mycorp' URI. |
|