It is possible to style HTML elements that have specific attributes or attribute values.
The [attribute]
selector is used to select elements with a specified attribute.
The following example selects all elements with a target attribute:
The [attribute="value"]
selector is used to select elements with a specified attribute and value.
Selects all <a>
elements with a target="_blank"
attribute:
The [attribute~="value"]
selector is used to select elements with an attribute value containing a specified word.
The following example selects all elements with a title attribute that contains a space-separated list of words, one of which is "flower":
The [attribute|="value"] selector is used to select elements with the specified attribute, whose value can be exactly the specified value, or the specified value followed by a hyphen (-).
The value has to be a whole word, either alone, like class="top", or followed by a hyphen( - ), like class="top-text".
The attribute selectors can be useful for styling forms without class or ID: