back

Attribute

You can select HTML elements according to the attributes they have.
The basic syntax to do this in CSS is to put the attribute in square brackets after the element, along with at least one of the below options, followed by the value of the attribute.
(1) The first is when the attribute exactly matches a value. To do this use ( = ).
(2) The second way is used if the attribute has multiple values (separated by spaces). To do this use ( ~= ).
(3) The third way is used if the attribute either matches the value or the value is followed by a dash ( - ). To do this use ( |= ).
(4) The final way is to select any element that has a particular attribute defined. To do this just put the attribute within the square brackets like so: [attribute].

Example