To target multiple classes with the same prefix, you'd typically have to resort to brittle attribute selectors. To make things easier, CSS is getting a new selector: the “Class Prefix Selector” (`.foo-*`). Check brm.us/class-prefix... to get the details. (Browser Support: None 😛 — just resolved!)
Post
brm.usThe Future of CSS: Target Multiple Classes with the Class Prefix SelectorTo target multiple classes that share the same prefix, you'd typically have to resort to brittle attribute selectors or add extra base classes to your markup. To make things easier, CSS is getting a n...
I updated the post to include selector benchmark results: gist.github.com/bramus/1de3b...
gist.github.com`.btn` vs `[class^="btn-"]` vs `[class*=" btn-"]` performance`.btn` vs `[class^="btn-"]` vs `[class*=" btn-"]` performance - benchmark-results.txt
In other words, since `[attr|=val]` was intended for possibly hyphenated BCP47 codes in `hreflang` etc., `[class|=foo]` matches the prefix even if it stands alone, which `.foo-*` is designed not to do. `:is([class^="foo-"], [class*=" foo-"])` also matches when nothing follows the hyphen.
0 reposts0 likes
I added a section to the post about the |= not being a good solution here: www.bram.us/2026/08/20/t...
bram.usThe Future of CSS: Target Multiple Classes with the Class Prefix SelectorTo target multiple classes that share the same prefix, you'd typically have to resort to adding an extra base classes to your markup or to using badly performing attribute selectors. To make things ea...