Use CSS types instead of new Tailwind specificity for better language alignment #16971
brandonmcconnell
started this conversation in
Ideas
Replies: 1 comment
-
Seems like a reasonable suggestion. For reference, the types CSS supports are specified in the https://drafts.csswg.org/css-values/ specification and syntax strings are specced in https://drafts.css-houdini.org/css-properties-values-api/#syntax-string. As for |
Beta Was this translation helpful? Give feedback.
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
-
Tailwind CSS v4's
--value()
syntax introduces types such asinteger
andpercentage
, among others (I don't see them all documented anywhere I can easily see in the official docs).It might be beneficial, if it's feasible in terms of effort and performance, to refactor this approach to more closely align with the actual types already supported in the CSS language itself, which supports over 50 predefined types and also supports joins like
small | medium | large
and the combination of types like<length-percentage>
(a type that can accept a length or a percentage as a value).More documentation on that can be found here:
percentage
types)<length-percentage>
<frequency-percentage>
<angle-percentage>
<time-percentage>
@property
syntaxsyntax: "<length> | <percentage>";
syntax: "<color>+";
syntax: "<length>#";
syntax: "small | medium | large";
syntax: "<length> | auto";
syntax: "*";
Alternatively, Tailwind CSS could support the existing types as a faster and built-in types system but also allow for explicit CSS data types for greater specificity and type checking.
To quickly distinguish these types, Tailwind CSS could also employ the same
type()
function seen in Chromium/Blink's recent implementation of the long-awaitedattr()
function (specification | MDN).Example:
Usage for common CSS data types:
Not needed when parsing integers as CSS units:
Read more about
attr()
here: Chrome for Developers > Blog > CSS attr() gets an upgradeHow this could look in Tailwind CSS v4
Instead of this:
One could write this:
Thanks to @bramus for writing up such a good article on Chrome's new
attr()
function, which introduced some of the syntax core to this proposal.Beta Was this translation helpful? Give feedback.
All reactions