3 ms·
My CSS property ordering preferences have changed a lot over the years, through some of those I see expressed in other comments: - by category (display, positi
by eyelidlessness 5y ago
My CSS property ordering preferences have changed a lot over the years, through some of those I see expressed in other comments:
- by category (display, position, etc)
- outside in
Then onto a variety of team preferences. Then I didn’t touch CSS for several years, as my “full stack” career became increasingly backend focused.
A previous team during that period had very strong (and sometimes idiosyncratic) code style preferences. I eventually cobbled as much of it as possible in an effort to remove those discussions from review so we could focus on more substantive discussion. But some of their preferences sank in and became my own. Of those less idiosyncratic, alphabetically ordering object properties (although I still prefer to make meaningful exceptions, eg for identifying keys or making the most important assignment most prominent) and aligning values really stuck. Both of which I had previously strongly disliked.
Anyway, when I left that job and returned to web dev, my instinct was: I want CSS properties to be alphabetized, but I’m sure it’ll never work. But after trying it, I’ve found it almost always does work!
The article gets at all of the cases I’ve encountered where it doesn’t, so I’ll defer to it. But I did want to add an anecdata as a previously skeptical convert.
Edit to add: and yes I agree with all of the comments saying this (or whatever ordering and any other code style preference) should be automated. Not just because I agree that improves the quality of review and diffs and reduces cognitive load, but also because meaningful exceptions are really hard to keep in mind under the best circumstances. Tools are not just there to do the chore, they’re also there to catch mistakes.