Case Insensitive CSS Attribute Selector

Date:

Share post:

CSS selectors never cease to amaze me in how powerful they can be in matching complex patterns. Most of that flexibility is in parent/child/sibling relationships, very seldomly in value matching. Consider my surprise when I learned that CSS allows matching attribute values regardless off case!

Adding a {space}i to the attribute selector brackets will make the attribute value search case insensitive:

/* case sensitive, only matches "example" */
[class=example] {
  background: pink;
}

/* case insensitive, matches "example", "eXampLe", etc. */
[class=example i] {
  background: lightblue;
}

The use cases for this i flag are likely very limited, especially if this flag is knew knowledge for you and you’re used to a standard lower-case standard. A loose CSS classname standard will have and would continue to lead to problems, so use this case insensitivity flag sparingly!

Request Metrics real user monitoring

Source link
spot_img

Related articles

Weekly Update 480

Well, I now have the answer to how Snapchat does age verification for under-16s: they give an underage...

Sharkoon Rebel P15 750W, An Inexpensive Way To Get Solid Power

Nothing But The Basics And A Cybenetics Gold Rating The price of building your own PC keeps rising, to...

Today’s NYT Mini Crossword Answers for Dec. 2

Looking for the most recent Mini Crossword answer? Click here for today's Mini Crossword hints, as well as our daily answers...