Skip to content

[Proposal] With all class names, find a balance between consistency, ease of use for newcomers, and ease of customization #1277

@AlexVipond

Description

@AlexVipond

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-xs in particular feel super intuitive.
  • Easy to be semantic, e.g. tracking-wide and leading-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, and leading-relaxed are 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 -0 to "unset" all properties, instead of trying to remember which should be -none and 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, and mt-16 become mt-8, mt-9, and mt-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 becomes rounded-2, and the default shadow becomes shadow-1.
  • Not easy to guess how much your design will be affected by incrementing the class name. With mt-10, mt-12, and mt-16, you have a sense that you're adding progressively larger amounts of spacing, but with mt-8, mt-9, and mt-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-25 for opacity: 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, and mt-16 make it clear that you're adding progressively larger amounts of spacing.
  • Very easy to name your custom values
  • You can use -0 to "unset" all properties, instead of trying to remember which should be -none and 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-32 exists, but mt-36 does 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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions