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 is when the attribute at least partially matches a value. To do this use (*=) .
(3) The third is when an attribute begins with a certain value. To do this use ( ^= ).
(4) The fourth is when the attribute ends with a certain value. To do this use ( $= ).
(5) The fifth way is used if the attribute has multiple values (separated by spaces). To do this use ( ~= ).
(6) The sixth way is used if the attribute either matches the value or the value is followed by a dash ( - ). To do this use ( |= ).
(7) 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