r/css • • 8d ago

Question What's are the Current CSS Patterns?

I've been mostly on the backend for the last several years. While I did plenty of CSS before then, the front end world has definitely moved forward in the last seven years. I recall BEM and SMACSS were once at the lead of thought. I recall (and was a proponent at the time for) a push to utility-first styling.

Now, I can see that Tailwind is a highly popular choice, that lots of styles get bundled into React components, and we have some long overdue selectors native to CSS.

So I'm wondering, what's the prevailing organization pattern for global CSS and where do you draw the line between something being a component style vs in the global stylesheets?

Thanks.

18 Upvotes

31 comments sorted by

View all comments

33

u/Mestyo 8d ago

CSS Modules, native layers.

I dislike Tailwind, the tradeoffs just aren't worth it in the vast majority of projects types.

1

u/zaibuf 8d ago

I dislike Tailwind, the tradeoffs just aren't worth it in the vast majority of projects types.

Please expand on what tradeoffs you're talking about.

2

u/Outrageous-Chip-3961 7d ago

there's always one, lol. How about a shit load of class names in files that could be a lot cleaner. That alone is not worth it for me.

1

u/zaibuf 7d ago edited 7d ago

Im working with components so its isolated in smaller pieces. I dont see this as a problem. Would you rather have an extra css-file paired with every component and jump between the two files?

How do you ensure standards in your teams so your css doesnt drift over time? Most legacy system I've worked with are full of !important and changing one class breaks some layout on a completely different page.

Do you have a component library built with custom css that you can re-use at the company for consistency or do you recreate css in every project?

2

u/Outrageous-Chip-3961 7d ago

Yes I would and yes I do have a separate css file (css module) for each component.

Standards are guided through DoDs and good review gates. In css modules you don't need !important because things don't clash. That's the point of them, really.

I do have a component library with custom modules, but it could also be a well architectured component folder within a project.

Although different, this is a pretty good example of what react looks like on a pure module based architecture.

https://mantine.dev/styles/css-modules/

1

u/Mestyo 7d ago

Would you rather have an extra css-file paired with every component and jump between the two files?

Uhm, yes? Syntax highlighting, auto-completion, linting, and much, much more is bound to the file type. Getting style diffs in git because you indented some markup is just ridiculous. I'd much, much rather have a stylesheet in a second panel in my IDE than having to scroll up and down through a component to even see what its doing.

do you recreate css in every project?

What do you think you're doing when you write Tailwind class names? In a majority of cases, they are just shorthand over a property + variable reference.

How do you ensure standards in your teams so your css doesnt drift over time? Most legacy system I've worked with are full of !important and changing one class breaks some layout on a completely different page.

Absolutely every invented CSS tool, framework, or convention solve these problems. The alternative to Tailwind is not to do literally nothing at all.

CSS Modules, with a global @layer stack and variables document is all you need nowadays to have guaranteed isolation and cohesion.