Allow trailing dash in functional utility names#19696
Conversation
The `isValidFunctionalUtilityName` function rejected utility names where the root ended with a dash after stripping the `-*` suffix. This prevented valid use cases like `@utility border--*` where the double dash serves as a visual separator between the CSS property and a value scale. The stated concern was that a utility like `border--*` could match the bare class `border-` when using default values. However, the candidate parser's `findRoots` function already handles this edge case by rejecting empty values (line 887: `if (root[1] === '') break`). The Oxide scanner also already extracts double-dash candidates correctly, as confirmed by existing tests (`items--center`). This enables design systems that use double-dash naming conventions for semantic color scales (e.g. `border--0` through `border--10`), where the double dash cleanly separates the property name from the scale value.
|
Thanks for raising this @kirkouimet - we are experiencing the exact same issue with 4.2.0. Our usage and patterns are as you have described we use it for colour utilities along with some others were we prefer the class='bg bg--token fg fg--token': |
RobinMalfait
left a comment
There was a problem hiding this comment.
Aha, I wish we didn't ship support for this in the first place. But you're right this used to work in previous versions just fine so going to allow it for backwards compatibility.
We might revisit this in Tailwind CSS v5, but we also don't like breaking things so it might work like this forever who knows. For now, going to accept it.
Thanks!
|
No actionable comments were generated in the recent review. 🎉 WalkthroughThis pull request modifies the utility name validation logic in TailwindCSS to permit trailing dashes in functional utility names and double dashes within root names. Changes include updating the validation functions 🚥 Pre-merge checks | ✅ 2✅ Passed checks (2 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. Tip Issue Planner is now in beta. Read the docs and try it out! Share your feedback on Discord. Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
|
@RobinMalfait thank you, really appreciate the quick review and merge. Wanted to share some context on why we landed on this pattern. We use semantic color scales (0-10) for theming, where a single class like border--2 resolves to different values in light and dark mode. The double dash separates the CSS property from the scale index, so the theme layer controls the actual color. The alternative with single dash collides with Tailwind's built-in utilities (border-0 is border-width), and the standard Tailwind approach of border-gray-200 dark:border-gray-700 doubles every color class. With this pattern a dense className string like border border--0 handles both modes in one declaration, and the scale values are immediately scannable. So the double dash isn't a stylistic choice on our end, it's the minimal syntax that lets semantic theming coexist with Tailwind's existing namespace. Thanks again for keeping it supported. |
Problem
Tailwind 4.2.0 introduced stricter
@utilityname validation (#19524) that rejects functional utility names where the root ends with a dash after stripping the-*suffix. This breaks a valid and useful naming pattern where a double dash separates the CSS property from a value scale:This produces:
border--0,border--1,border--2, etc.The error message is:
Why this pattern matters
The double-dash convention creates a clear visual grammar in class names. The first segment names the CSS property, and the double dash separates it from the semantic scale value. In a dense className string like
border border--0 background--0 content--4, the scale values (0, 0, 4) are immediately scannable, distinct from the single-dash property names around them.This pattern is actively used in production design systems for semantic color scales (background, content, border, shadow) with values from 0-10.
Why the restriction is unnecessary
The validation comment states the concern is that
border--*could match the bare classborder-when using default values. However, this edge case is already handled:findRootsincandidate.ts(line 887) already rejects empty values:if (root[1] === '') break("items--center", vec!["items--center"])The candidate parser and scanner both handle this case. The validation was an overcorrection.
Changes
isValidFunctionalUtilityNameinutilities.ts['foo--*', false]to['foo--*', true]@utility border--*compiles correctly with theme valuesTest results
All 4121 tests pass across the tailwindcss package, including the new integration test.