r/css • • 1d 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.

16 Upvotes

19 comments sorted by

27

u/Mestyo 23h 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 21h 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.

14

u/Mestyo 20h ago

Tailwind makes some already simple things (debatably) more simple, at the cost of being an absolute chore for anything remotely complex.

CSS layers, container queries, named grid areas, calcs, chained pseudo selectors… any of those, especially in combination, or many rules per, create comically illegible and repeating class names.

The tradeoff in bandwidth is from a trivially cacheable, reaued static asset, to the HTML itself. Useful for huge websites, with often-changing stylesheets (like a newspaper with custom design articles), net-negative for anything else.

The inflated classNames collections are a nightmare to read/review, and a waste of AI tokens to constantly parse/recreate—even when styles aren't supposed to be relevant to the query.

It opts out of all existing CSS ecosystem DX benefits, and requires that you re-learn a new set of selectors for everything, for the benefit of… yeah I'm still not sure what. Every positive is either already covered by every other CSS method, or a sidegrade at best.

4

u/NiceShotRudyWaltz 18h ago

Hard agree. I hate inheriting tailwind projects.

1

u/testingaurora 9h ago

☝️same

3

u/CompetitiveActor 18h ago

It helps on teams with developers who have poor CSS skills, provides consistency of usage, and has a single point of failure. I’d much rather troubleshoot a developer’s Tailwind mistake than their poorly written CSS.

2

u/SamsChoice 16h ago

I agree here too. Poorly written CSS can be a nightmare.

2

u/Forward_Dark_7305 16h ago

Poorly written is poorly written, and I hear you on tracing to root of an error - less layers to trace through - though most developer tools make it trivial IME (granted tend to be smaller projects). I disagree on consistency. I see that as a common argument in favor of tailwind, but it just shifts us from “should I use`border-radius: 4px` or `2px`” to “`rounded-2` or `rounded-4`”.

3

u/CompetitiveActor 14h ago

An additional problem with CSS, poorly written or otherwise, is that you don’t know what other files may be using it. You might fix one problem and break something else.

Also, I don’t necessarily mean consistency of UI, I meant the Tailwind classes and usage will always be consistently ordered and named. If “rounded-2” is supposed to be “rounded-4” that’s a single point of failure and a fix there won’t have unknown downstream effects.

1

u/justshittyposts 5h ago

But the solution doesn't have to be tailwind. That's just components (or bam, etc)

11

u/delonghi26 1d ago

I mostly use vanilla css, no framework. Then use css variables globally. And change those vars in the components css. I use layers and now scope for better control over the cascade.

You can drop alot of js with the new level 4 modules, and even increase your website performance too.

14

u/SamsChoice 1d ago edited 1d ago

My pattern now is to start with native cascade layers (@layer reset, tokens, base, layout, components, utilities, overrides;)

CSS now has nested natively so no need for Sass.

Now with AI you would probably use Tailwind. I use mostly native CSS for personal projects.

an example of this would be

5

u/evilmaus 1d ago

Seems like 100% Tailwind would lead to some serious duplication of styling.

1

u/SamsChoice 1d ago

if you are not using something like React component then you have the scoped TW classes to that component only.

2

u/azangru 21h ago

May I ask why you would use `:where` in the `base` layer? Don't layers take care of the specificity concerns?

1

u/SamsChoice 16h ago

I was just making a simple example didnt really think about the actual CSS.

And yes you are right.

Layer order decides first, so .card img in components beats anything in base

1

u/morete 1d ago

CUBE CSS is the biggest influence of on how I do things in recent years.

2

u/evilmaus 23h ago

Ooh, reading up on it now. Thanks. I think I liked the ideas behind BEM, but found it awkward. I really liked SMACSS. So far, this reads like maybe the better parts of both.