How to style data-value attributes with CSS

Here is a great way to style any data-attributes using CSS properties.

Here is the article source courtesy of CCS-Tricks.

[data-value] {
  /* Attribute exists */
}
[data-value="foo"] {
  /* Attribute has this exact value */
}
[data-value*="foo"] {
  /* Attribute value contains this value somewhere in it */
}
[data-value~="foo"] {
  /* Attribute has this value in a space-separated list somewhere */
}
[data-value^="foo"] {
  /* Attribute value starts with this */
}
[data-value|="foo"] {
  /* Attribute value starts with this in a dash-separated list */
}
[data-value$="foo"] {
  /* Attribute value ends with this */
}

Man looking at a laptop screen coding CSS

Leave the first comment

Related posts