Skip to content

Instantly share code, notes, and snippets.

@parties
Created February 14, 2017 20:36
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save parties/a6347bcf1d791607f03997d03d61d3c3 to your computer and use it in GitHub Desktop.
Save parties/a6347bcf1d791607f03997d03d61d3c3 to your computer and use it in GitHub Desktop.
CSS Attribute Selectors Cheat Sheet
/* Courtesy of MDN: https://developer.mozilla.org/en-US/docs/Web/CSS/Attribute_selectors */
div[attr] { /* "has attr" - element contains 'attr' attribute, value does not matter. */ }
div[attr=value] { /* "exactly" - attr is exactly value. */ }
div[attr~=value] { /* "contains" - attr is a whitespace-separated list of words, one of which is "value". */ }
div[attr|=value] { /* "exactly or begins with `value-` - attr can be exactly "value", or it can _begin_ with "value" immediately followed by “-” (U+002D). */ }
div[attr^=value] { /* "starts with" - attr's _first_ value is prefixed by "value". */ }
div[attr$=value] { /* "ends with" - attr's _last_ value is suffixed by "value". */ }
div[attr*=value] { /* "contains" - attr contains at least one occurrence of "value" as a substring. */ }
div[attr(~|^$*)=value i] { /* "case-insensitive <query>" - applies a case-insensitive search on the query (any of the above examples will work, just end the selector with 'i' */ }
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment