I like splitting the classes into logical groups. In this case, Iām grouping by: 1) base positioning, 2) flex behavior, 3) effects, and 4) colors.
Finally, the filter in the tw function allows for easy conditional classes:
class={tw(kind === "something" && "m-4 p-4")}
I also use Biome, which has a work-in-progress but already quite good class sorter for Tailwind [1]. This keeps the code tidy by applying a logical sort order to each string passed into the tw function.
You can think of Tailwind as the "APL of CSS." A single utility class can generate a lot of CSS for you, which is one advantage.
The key benefit of Tailwind is that it co-locates your CSS with your HTML, reducing cascading issues and improving maintainability.
Like any codebase, you can use your tools to add more structure and meaning.
For example, I like using a tw function like this:
Using the tw function, your example classes would look something like this: I like splitting the classes into logical groups. In this case, Iām grouping by: 1) base positioning, 2) flex behavior, 3) effects, and 4) colors.Finally, the filter in the tw function allows for easy conditional classes:
I also use Biome, which has a work-in-progress but already quite good class sorter for Tailwind [1]. This keeps the code tidy by applying a logical sort order to each string passed into the tw function.--
1: https://github.com/biomejs/biome/pull/1362