-
-
Notifications
You must be signed in to change notification settings - Fork 4.8k
Closed
Description
I've seen this discussion pop up in a bunch of other threads both here and on Twitter. Just wanted to open a dedicated issue so we can give it proper consideration as we approach Tailwind 2.0.
General idea: people have proposed moving to linearly incrementing, number-based class names (text-1, text-2, etc.) instead of word-based class names (text-xs, text-sm, etc.) and non-linearly incrementing number-based class names (m-10, m-12, m-16, m-20, etc.).
I've experimented a lot with this and have given some thought to the trade-offs. From what I've seen, we all agree that these things are important:
- Class names should be reasonably consistent across all of Tailwind
- Tailwind should be easy for newcomers to use
- Tailwind should be easy to customize
And here's how the class naming systems stack up in terms of those priorities:
Word-based
Pros:
- Arguably the easiest naming system for Tailwind newcomers. T-shirt size classes like
text-xsin particular feel super intuitive. - Easy to be semantic, e.g.
tracking-wideandleading-relaxed.
Cons:
- Hard/impossible to find names for custom, in-between values (
xs.5?small-and-a-half?). Right now, this is why spacing utilities completely ditch the words altogether and go with a scaled number-based approach. - Easy to fall into the trap of making words inconsistent across different properties. Case in point:
text-lg,tracking-wide, andleading-relaxedare all next size up from the default size.
Numbers that always increment by 1 (or 100)
Pros:
- Arguably the easiest naming system once you get past the initial Tailwind learning curve and get acclimated to the Tailwind way of designing things.
- You can use
-0to "unset" all properties, instead of trying to remember which should be-noneand which should be-0. - Very easy to name your custom values.
- Extremely easy to guess the "next" class when you're designing and just need to bump the size up or down for any given property.
mt-10,mt-12, andmt-16becomemt-8,mt-9, andmt-10.
Cons:
- Not always easy to remember where the "default" value is. When you apply this naming scheme to all properties, the default font-size becomes
text-3, the default border radius becomesrounded-2, and the default shadow becomesshadow-1. - Not easy to guess how much your design will be affected by incrementing the class name. With
mt-10,mt-12, andmt-16, you have a sense that you're adding progressively larger amounts of spacing, but withmt-8,mt-9, andmt-10, you'd expect linear increments in the underlying spacing values, and you might be confused when that doesn't happen. - Sucks for opacity. Don't ever make me use something other than
opacity-25foropacity: 0.25.
Numbers that always increment based on the change in the underlying values
Pros:
- Keeps you grounded in how much size you're adding to a design.
mt-10,mt-12, andmt-16make it clear that you're adding progressively larger amounts of spacing. - Very easy to name your custom values
- You can use
-0to "unset" all properties, instead of trying to remember which should be-noneand which should be-0.
Cons:
- Sometimes difficult to remember, even for Tailwind veterans.
- Big learning curve for Tailwind newcomers, who need to spend a lot of time in the docs until they start to remember that
mt-32exists, butmt-36does not. - Keeps you grounded in how much size you're adding to a design. This is both a pro and a con—the downside is that it forces you give some thought to the underlying values in Tailwind's design system, which are implementation details for Tailwind users who aren't customizing the system.
mrcsmcln, lkraav, eyalev and suddhammrcsmcln
Metadata
Metadata
Assignees
Labels
No labels