DEV Community

Stefan Judis
Stefan Judis

Posted on • Originally published at stefanjudis.com on

3 1

TIL: The CSS attribute selector has a case-insensitive mode

I'm following the caniuse.com project on GitHub which means I get notifications about additions to the web platform and updated browser support. Today, I stumbled upon an issue including new CSS Level 4 selectors that are or will be included on caniuse.com.

It turns out there are a lot of new selectors on their way, and one interesting one is a flag which makes attribute selectors case-insensitive.

/**
 * matches:
 * <div class="foo">...</div>
 * <div class="Foo">...</div>
 * <div class="fOo">...</div>
 * ...
 */
[class=foo i] {
  color: red;
}
Enter fullscreen mode Exit fullscreen mode

Only downside is, that Edge is not supporting this selector yet.

If you want to play around with this, I created a quick codepen. The only case I can think of this for this is when you have to deal with user-generated content, and the possibility is quite high the users enter not accurate data. Would love to learn more about other use cases for this – if you have an idea, please let me know.

Edited: Dominik pointed out that this could be indeed useful for user-generated content in input fields using the value attribute.

/**
 * matches:
 * <input value="hello world">
 * <input value="hello World">
 * <input value="hElLo WoRlD">
 * ...
 */
[value="hello world" i] { /* ... */ }
Enter fullscreen mode Exit fullscreen mode

Hostinger image

Get n8n VPS hosting 3x cheaper than a cloud solution

Get fast, easy, secure n8n VPS hosting from $4.99/mo at Hostinger. Automate any workflow using a pre-installed n8n application and no-code customization.

Start now

Top comments (0)

Billboard image

The Next Generation Developer Platform

Coherence is the first Platform-as-a-Service you can control. Unlike "black-box" platforms that are opinionated about the infra you can deploy, Coherence is powered by CNC, the open-source IaC framework, which offers limitless customization.

Learn more

👋 Kindness is contagious

Please leave a ❤️ or a friendly comment on this post if you found it helpful!

Okay