You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Hi Tailwind Team,
I have an idea for improving tailwind readability and DX. New attribute syntax like class:<prefix> to improve template readability in Tailwind.
The idea is to factor out common state/modifier prefixes (hover:, focus:, dark:, md:, custom ones, etc.) into their own attributes.
Readability: Reduces repetition in long class strings, making complex states/responsive styles easier to manage and read, especially across multiple lines.
Component Authoring: A class:default attribute could define base styles, potentially simplifying how className props are merged and reducing the need for runtime utilities like cn/tailwind-merge. based on experimental “default” state idea that was designed for V4.
Further Composition Idea:
The "default" state could behave like "has-*" states, meaning it could be combined with other states.
We could potentially extend this by allowing combinations like class:default-<prefix>. This would group the base styles and their variants together, enhancing clarity:
constButton=({ className, ...props})=>(<buttonclass={className}// User overrides and custom stylesclass:default="px-4 py-2 bg-blue-500"// Base stylesclass:default-hover="bg-blue-600"// Base hover stylesclass:default-disabled="opacity-50"// Base disabled stylesclass:dark="bg-gray-800"// Dark mode overrides/>);
This pattern will be transformed to a correct class name and after Tailwind can generate the css files.
<buttonclass="px-4 py-2 bg-blue-500 default-hover:bg-blue-600 default-disabled:opacity-50 dark:bg-gray-800">
Click Me
</button>
This introduces a dedicated syntax rather than extending variant composition directly in the class string. It would require changes to how Tailwind scans templates but could offer significant DX improvements by grouping styles logically.
reacted with thumbs up emoji reacted with thumbs down emoji reacted with laugh emoji reacted with hooray emoji reacted with confused emoji reacted with heart emoji reacted with rocket emoji reacted with eyes emoji
-
Hi Tailwind Team,
I have an idea for improving tailwind readability and DX. New attribute syntax like
class:<prefix>
to improve template readability in Tailwind.The idea is to factor out common state/modifier prefixes (
hover:
,focus:
,dark:
,md:
, custom ones, etc.) into their own attributes.Example:
Benefits:
class
strings, making complex states/responsive styles easier to manage and read, especially across multiple lines.class:default
attribute could define base styles, potentially simplifying howclassName
props are merged and reducing the need for runtime utilities likecn
/tailwind-merge
. based on experimental “default” state idea that was designed for V4.Further Composition Idea:
The "default" state could behave like "has-*" states, meaning it could be combined with other states.
We could potentially extend this by allowing combinations like
class:default-<prefix>
. This would group the base styles and their variants together, enhancing clarity:This pattern will be transformed to a correct class name and after Tailwind can generate the css files.
This introduces a dedicated syntax rather than extending variant composition directly in the class string. It would require changes to how Tailwind scans templates but could offer significant DX improvements by grouping styles logically.
What are your thoughts on this direction?
Thanks!
Beta Was this translation helpful? Give feedback.
All reactions