Skip to content
This repository has been archived by the owner on Mar 6, 2020. It is now read-only.

Order class names in markup. What's your secret? #124

Open
adevade opened this issue Feb 23, 2018 · 8 comments
Open

Order class names in markup. What's your secret? #124

adevade opened this issue Feb 23, 2018 · 8 comments

Comments

@adevade
Copy link

adevade commented Feb 23, 2018

Been trying out Tailwind for about a week now, and lovin' it!! 馃槏

Just wanted to see how everybody's sorting/ordering their classes in the markup. Sometimes the strings can get very long...

Outside of Tailwind, I've been grouping my CSS properties like in this chapter from the SMACSS book (box, border, background, text, other) and then alphabetically inside each group for several years.
It has worked wonderfully in traditional CSS and I've been trying to order Tailwind's classes in the markup the same way, but I don't feel like it translates well to this workflow.

Do you have any special tricks for ordering the classes? All alphabetically? All variations (hover, responsive, etc) at the end? Variations directly after the class you're modifying? One class per line?
Please leave a reply below, and we can all maybe learn something from each other! 馃帀

@luizbills
Copy link

I basically always put "theming" (color, background, borders) it last. But the Basscss suggest a good order: http://basscss.com/v7/docs/guides/basics/#order

@glennabaron
Copy link

I use (two) spaces and slashes to help visually divide groups of like-classes (all flex classes together, spacing classes grouped together, etc.). Responsive classes follow any related non-responsive class. For example, something like:

flex sm:inline-flex items-center / bg-blue / text-white text-sm font-bold / px-4 py-3

@stefanbauer
Copy link

stefanbauer commented Feb 23, 2018

The thing is: As long as you are developing your own stuff and are the only one who's working on the project it's up to you and no one cares about. You can group by position, typo, whatever. But when it comes, that a (larger) team is working on a project you have to ensure, that every single team mate knows the rule to have consistency over your project.

In that case I'd prefer something easy. If you define an order like:

  • Positions
  • Layout
  • Typo
  • Whatever

I can guarantee, that nobody cares because nobody remembers and they have to refer to the documentation all the time. So one easy way (even if you write regular css in your css files) I find, is, to order it alphabetically. It's not very logical and at the beginning it's strange to read. But the very big advantage is, everybody knows the alphabet. Or at least they should :) I promise you, with that in mind, you have a really straight consistency of code. But again, I apply that only if you work on larger teams.

If you are on a one-man show, do whatever you want, what you like and what you're used to. 馃憤

@XavRsl
Copy link

XavRsl commented Feb 23, 2018

Never heard of Typosilaycosta? It could be the name of a Greek village in the Ionian Islands, but it's not. It's just a way to remember Typography, Position, Layout, Colors, and State!

@jam1e
Copy link

jam1e commented Feb 23, 2018

I tend to place things alphabetically within each responsive class, that work from sm up to large. For example:

rounded w-full sm:border-t sm:mx-2 sm:my-4 lg:mx-4 my-5

@hacknug
Copy link

hacknug commented Mar 20, 2018

Duplicate of #97.

@dakshshah96
Copy link

I've been using Headwind for some time and love it!

Headwind is an opinionated Tailwind CSS class sorter for Visual Studio Code. It enforces consistent ordering of classes by parsing your code and reprinting class tags to follow a given order.

https://github.com/heybourn/headwind

@tqwewe
Copy link

tqwewe commented Jan 28, 2020

I hate to plug my own packages... but I've just published a tailwind classes sorter prettier plugin.

https://github.com/Acidic9/prettier-plugin-tailwind-classes-sorter

It will sort classes based on plugin name.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

9 participants