Exact Match — [attribute="value"]

Here we select the link with the exact href value "https://www.css-tricks.com", and change its color and font size. Notice that the link to the almanac is not styled.

CSS-Tricks

CSS-Tricks Almanac


Attribute Value Contains — [attribute*="value"]

Here we select the images with the full word or word fragment "art" in the alt text and give them an outline. Notice that the images with the alt text "abstract art" and "athlete starting a new sport" both get outlined.


Attribute Value is in Space-Separated List — [attribute~="value"]

In the list below, we select images with the word "art" in their alt attribute, either as the only value or as a whole word in a space separated list. Notice that the image with the alt text "athlete starting a new sport" is not outlined like it was in the "Attribute Contains" example.

abstract art something to eat athlete starting a new sport

Attribute Value Starts With — [attribute^="value"]

Here we select the images with alt text that starts with "art". Notice that the image with the alt text "artistic pattern" is selected, but the image with the alt text "Arthur Miller" is not because attribute selectors are case-sensitive.

artistic pattern a healthy meal Arthur Miller

Attribute Value is First in Dash-Separated List — [attribute|="value"]

Selecting the list item with a data-decade attribute that has "1900" as the only value or the first in a dash separated list. Notice that only the 2nd list item is selected. The first list item has "1900" in its data attribute value, but it's after the dash.


Attribute Value Ends With — [attribute$="value"]

In the paragraph below we select the link with the href that ends with "pdf" and apply an icon as :after content.

A humble digital file becomes self-aware and starts conversations with web developers. Read the fascinating account in example.pdf