Select all classes containing a keyword in CSS

Posted on: February 9th, 2023
By: Tadeo Martinez

Using “*” will select all the class names that contain that word, regardless of the position of the class name in the div.

[class*="keyword"]

/* <div class="col-lg-6 col-md-4 keyword-something"></div> */

You can also use this one:

[class^="keyword"]

/* <div class="keyword-something col-lg-6 col-md-4"></div> */

But this will only work if the keyword if the first keyword in the classes

Have any questions or comments? Write them below!


Leave a Reply

Your email address will not be published. Required fields are marked *