News for hackers. Stuff that matters.
Re:Tailwind vs. Semantic CSS by gherkinnn on Monday October 23, 2023 @03:49AM (#37982663)
This is one of the first Tailwind vs * articles that isn't bad. It makes a good case in the analysis.

For a lot of applications (like a blog), what the author calls "semantic CSS" is the right thing to do. But there comes a point at which it is no longer feasible. We have a long history of SMACSS, object oriented CSS, BEM, CSS Modules, scoped CSS, and now Tailwind to make it work.

> Because mastering CSS requires practice. It takes several failed attempts before you get it.

Explaining the popularity of something by simply proclaiming "git gud" isn't a very strong point. For newer CSS devs, it does take away the woes of clashing naming and a badly structured cascade. The rest remains and the results remain shite. Similarly, I haven't seen a pattern where good CSS authors do not like Tailwind.

Re:Tailwind vs. Semantic CSS by sbergot on Monday October 23, 2023 @04:25AM (#37982923)
No this article is flawed. It fails to recognize the fact that css and html are always coupled in one direction or another. With tailwind the css is fixed and the html is designed around it. With semantic the html is first created and then you write your css around it.

The fact is that updating css in a big project and a big team is very difficult. Rules are scoped globally. It only takes a junior making a few design mistakes and now you don't what you are going to break if you update anything.

With tailwind the css is fixed and will never change. So you just change your html and you know what to check/what to test again. For any medium to large project this is a big QA & time boon.

"just use code review, naming convention, xxx best practice". This argument is similar to "just don't make mistakes". Mistakes will be made. With semantic css you will suffer.

Re:Tailwind vs. Semantic CSS by tipiirai on Monday October 23, 2023 @04:32AM (#37982985)
Author here. You are right: HTML and CSS are always coupled. The major difference is that Tailwind embraces tight coupling and semantic CSS embraces loose coupling. Please check the "Best practises" section:

https://nuejs.org/blog/tailwind-vs-semantic-css/#best-practi...

Re:Tailwind vs. Semantic CSS by sbergot on Monday October 23, 2023 @04:51AM (#37983142)
This section is what I am talking about. You compare two methods of writing components and then declare that the tailwind version is tightly coupled but the semantic version is loosely coupled. In programming lingo this means tailwind is bad and semantic is good.

But you don't explain why the tailwind version is tightly coupled and the semantic version is loosely coupled. And you don't do it because it is simply not the case. The coupling between html and css is not tighter or looser. It just goes in a different direction.

> The semantic version, allows you to change the design of the gallery freely. You name the component and style it externally. With Tailwind the style cannot be separated from the structure.

Same with tailwind. You update your component to update its style. With semantic you can update the css rules without touching the html, but you don't know if this css change won't break another part of your design. If you have a simple html structure like a blog with very few components, then semantic works (but so does anything really). If you have lots of components and you need to update them in order to add new features, then semantic will bring more issues.

Re:Tailwind vs. Semantic CSS by tipiirai on Monday October 23, 2023 @04:54AM (#37983171)
So `<div class="gallery">` is loose coupling, because the styling is not coupled directly into the element. You can completely switch the gallery design, by switching (or overriding, or modifying) the external stylesheet.
Re:Tailwind vs. Semantic CSS by config_yml on Monday October 23, 2023 @05:20AM (#37983326)
I have rarely seen this work in practice in 20 years of CSS, but maybe in CSS Zen Garden. Yes, you can freely change the CSS. But usually changes are triggered by the HTML, like some information is added. This then requires you to change the CSS and likely break all sorts of other uses, which is not a problem with Tailwind.
Re:Tailwind vs. Semantic CSS by tempmac on Monday October 23, 2023 @06:56AM (#37983945)
hmm maybe IDE plugins can solve this? (eg. add a 'hover to show css' or 'expand css if I press ctrl+alt')

as for tailwild, I just can't bare its wide-ness - too many className attribute string going over 150~300 char widths, with some ternary operators mixed on top...

(seems vanilla-extract / ete have better DX, with occasional inlining for immediate deadlines)

Re:Tailwind vs. Semantic CSS by sbergot on Monday October 23, 2023 @08:19AM (#37984619)
The only way to know is to go to the page and inspect it using devtools. No Ide will be able to infer which rule is going to apply to any given element.

But the problem is that you need to make sure that a given css change is going to affect only a specific set of component. So you need to check all components. Since it will be too time consuming, you will probably skip this step and hope for the best (and do some QA to check that nothing is obviously broken).

Re:Tailwind vs. Semantic CSS by tempmac on Monday October 23, 2023 @09:13AM (#37985135)
hmm it might be possible with enough tooling:

- read from webpack's output

- read from css-in-js: emotion / vanilla-extract / etc

Re:Tailwind vs. Semantic CSS by kaba0 on Monday October 23, 2023 @11:53AM (#37987493)
Then you avoid the browser, by emulating half a browser.. which is still useless, because you have plenty dynamic state you can’t test this way.
Re:Tailwind vs. Semantic CSS by tipiirai on Monday October 23, 2023 @05:28AM (#37983383)
You can see this in practise here:

https://nuejs.org/@spotlight/

vs here:

https://nuejs.org/@base/

(the gallery component)

Re:Tailwind vs. Semantic CSS by HelloNurse on Monday October 23, 2023 @05:15AM (#37983299)
The coupling is in the right direction: designing possibly very advanced CSS to get a desired appearance from a given good markup, instead of compromising markup to simplify CSS.
Re:Tailwind vs. Semantic CSS by sbergot on Monday October 23, 2023 @06:06AM (#37983620)
The issue of this direction is if you need to update the markup, you will need to update the css, which is hard and risky because of css global scoping.
Re:Tailwind vs. Semantic CSS by HelloNurse on Monday October 23, 2023 @06:48AM (#37983893)
New and updated CSS rules should be usually needed for new "themes", exactly the type of change that semantic markup is robust against (e.g. placing image captions in a sidebar rather than below the respective images), and for backwards compatible extensions of the original design that add support for something new that will only be used in new markup in new pages (e.g. allowing small images inside paragraphs, meant to be displayed inline, in addition to large ones between paragraphs).

What kind of fragile markup and problematic CSS global rules are you worrying about?

Re:Tailwind vs. Semantic CSS by skydhash on Monday October 23, 2023 @07:20AM (#37984106)
> What kind of fragile markup and problematic CSS global rules are you worrying about?

I’m wondering that too. If I’m writing a SPA, styles are usually scopped to the component with a base styles for UI atomic elements. And some conventions around spacing. If it’s a website, it will be separated in layouts and small components Bootstrap-like. An update will be identified as a variant or a special case.

As for coding this, search all files is usually a godsend when refactoring. You can use ripgrep if the editor does not have a good implementation.

Re:Tailwind vs. Semantic CSS by sbergot on Monday October 23, 2023 @08:13AM (#37984555)
The author uses css targets like *body > header*. Search and replace won't be enough to tell you which components are affected by a given rule.
Re:Tailwind vs. Semantic CSS by sbergot on Monday October 23, 2023 @08:15AM (#37984583)
A lot of applications have a long lifetime. They are not shipped only once. If I want to add a new feature, say allow users to perform a new operation in an existing screen, I will have to update a few components for this.

You want to preserve the theme an consistency of the UI, but adapt its functionality. For this type of changes the semantic version is problematic.

Re:Tailwind vs. Semantic CSS by HelloNurse on Tuesday October 24, 2023 @07:55AM (#37997831)
Ordinary changes fall within the boundaries of the existing design system: for example, "a new operation in an existing screen" probably means adding instances of a few existing components (button, paragraph, title, section, pop-up submenu, etc.), with no impact on styles, not "updating" components.
Re:Tailwind vs. Semantic CSS by MaxArt2501 on Tuesday October 24, 2023 @02:21AM (#37995375)
I can't, for the sake of me, understand how some frontend devs still complain about CSS' global scope when style encapsulation exists and is widely adopted in a form or the other, either native (Shadow DOM) or emulated.

You don't like global styles? Don't use global styles, period.

Even without adopting Nue and staying on React, CRA and Next comes out with CSS Modules out of the box. Angular and Vue have their own equivalent.

Re:Tailwind vs. Semantic CSS by sbergot on Monday October 23, 2023 @06:04AM (#37983606)
It is still coupled because the css will need to know the html structure in order to work. If you update the html, you probably need to update the css.
Re:Tailwind vs. Semantic CSS by tobr on Monday October 23, 2023 @06:48AM (#37983884)
Both of them need to conform to the same allowed patterns of markup. I think we lack a kind of markup schema or type system that everything can be validated against, where we can verify that our design takes every state and permutation into account, and that both styling and content implements their part of it correctly.
Re:Tailwind vs. Semantic CSS by sbergot on Monday October 23, 2023 @08:08AM (#37984514)
tailwind doesn't need to know anything about your components.
Re:Tailwind vs. Semantic CSS by tobr on Wednesday October 25, 2023 @01:34AM (#38009484)
[delayed]
Re:Tailwind vs. Semantic CSS by tipiirai on Monday October 23, 2023 @09:17AM (#37985174)
It is _loosely_ coupled. I can switch the design completely without touching HTML.

If I modify the HTML structure, the component specification changes and CSS obviously needs to be updated.

Re:Tailwind vs. Semantic CSS by kaba0 on Monday October 23, 2023 @11:55AM (#37987525)
This is simply not true of any real-world application.
Re:Tailwind vs. Semantic CSS by crdrost on Monday October 23, 2023 @12:13PM (#37987756)
You will be more effective if you deploy your words more carefully.

Loose coupling vs tight coupling has an established meaning ≈ “if a change to module X causes a failure in module Y, then we say X and Y are tightly coupled.” This has some “knock-on” effects that you are trying to gesture at, like, “If two modules are tightly coupled then because of that tight coupling we usually have to coordinate deployments between them both.” And then you're like “I can ship new CSS without having to coordinate a deployment of HTML, that must be loose coupling then!”

But this is a sloppy way to use the language, because in the one case you have one module, and in the other case you have two: there is no coupling in the Tailwind case because there is nothing to be coupled because it all ships as one module, then you construct a more modular approach, one with two modules in fact, and these modules are (depending on how you squint at it given that we are doing decorative programming and there are no explicit errors) in fact “tightly coupled”—the semantic HTML essentially provides a customized API which the CSS uses by hooking into; this is a common form of tight coupling in microservice deployments for example.[1]

So you are actually looking at, one module plus a static asset that defines a common language, vs. two modules that are tightly coupled, and declaring that the two modules are “more loosely coupled” and this is somewhat of a nonsense thing to say. Like I get what you were going for, I didn't write this as a top level complaint because I understand what you meant, but here in the thicket of comments I see that you are not communicating well with your interlocutor because of this sloppiness and language, you might want to pivot?

[1] This point about microservices is likely to outrage a random passerby, look I am sure that your microservices use RPCs against HTTP APIs in a way that doesn't cause you much grief in having to update multiple modules in one commit (if monorepo) or stage “topics” (Gerrit’s term) where you carefully have to merge 2 or 3 pull requests to different repositories all at the same time (if multi-repo). But even though your microservices are loosely coupled, I have worked on very similar architectures where we did have to stage topics and if you didn't then changes to service X would break service Y, “We’ll ship a new value for this enum, that requires changing the common schema repo, which requires updating every microservice that looks at that enum so that it doesn't have a deserialization failure ‘this is not an allowed value for that enum’ when the new values start rolling out, the ones that actually switch() or if() on that enum need to be updated to do the right thing, oh, I missed one because it relies on the contract that if enum == x then fieldA is set but if enum == y or z then fieldB is set but now when enum == q neither fieldA nor fieldB is set...” and I am happy that you haven't had these problems but yeah, some microservices are tightly coupled by this definition.

Re:Tailwind vs. Semantic CSS by kaba0 on Monday October 23, 2023 @11:51AM (#37987436)
So what does it mean? You want the structure of your HTML to say the browser, that here is anything? Does your designer just give you a design with a huge blank rectangle in the middle? When does it ever make sense?

Isn’t it much more meaningful to create a <gallery> component (it can be done through a template-engine, react, whatever, that’s another point).

I mean, sure, we could just program with void pointers everywhere, but is it really a good idea?

Re:Tailwind vs. Semantic CSS by gherkinnn on Monday October 23, 2023 @04:30AM (#37982959)
> "just don't make mistakes". Mistakes will be made.

Is kinda what I said.

Re:Tailwind vs. Semantic CSS by pas on Monday October 23, 2023 @07:28AM (#37984174)
> Rules are scoped globally.

Isn't "CSS scoped to components" nowadays a basic feature of frameworks?

Re:Tailwind vs. Semantic CSS by sbergot on Monday October 23, 2023 @08:16AM (#37984594)
The author is advocating for rules like "body > header" in separate css files.
Re:Tailwind vs. Semantic CSS by tipiirai on Monday October 23, 2023 @08:28AM (#37984710)
Indeed! I'm a freak using CSS as intended :)
Re:Tailwind vs. Semantic CSS by kaba0 on Monday October 23, 2023 @11:56AM (#37987544)
The problem is that CSS’s intended usage is broken, and never lived up to expectations.
Re:Tailwind vs. Semantic CSS by tipiirai on Monday October 23, 2023 @12:09PM (#37987711)
I think CSS does a good job at separating structure from presentation. Or what do you think was the original intention? Do you think Tailwind fixed the core issue with CSS?
Re:Tailwind vs. Semantic CSS by kaba0 on Monday October 23, 2023 @01:38PM (#37988972)
I really recommend you reading the blog post by tailwind’s creator himself: https://adamwathan.me/css-utility-classes-and-separation-of-...

Your “semantic” CSS depends on your HTML structure. Tailwind’s HTML depends on a fixed set of CSS styles. None is any more coupled than the other, it’s just that the direction of the dependence is different.

Depending on what is expected to change more, both can be a valid approach: e.g. for a blog post that only uses heading, emphasis, link, styling it from CSS alone is definitely the best choice (that’s what it was developed for). But I would argue, most real-world web applications see more HTML-changes, and thus the other direction may make more sense.

Re:Tailwind vs. Semantic CSS by tipiirai on Monday October 23, 2023 @02:07PM (#37989352)
Fully aware of this post. It's well written and I can see why people follow his stance. But I don't share the same history / experiences with semantic CSS than Adam. I genuinely prefer to separate structure from styling and not end up to this situation:

https://nuejs.org/blog/tailwind-vs-semantic-css/img/markup-b...

Re:Tailwind vs. Semantic CSS by bryanrasmussen on Monday October 23, 2023 @05:53AM (#37983531)
>Similarly, I haven't seen a pattern where good CSS authors do not like Tailwind.

well I haven't used Tailwind but from the examples I've seen I would hate it, and from what I can see I would hate it for the same reason that I hate all CSS abstractions I've worked with - because they limit what I can do with CSS in the interest of making it easier for other people who are not that good with CSS to get their work done OR it will require me to do things in a particular way when I believe I know a far better way of doing them.

Now I'm not arguing I am a good CSS author, I do lack some things (like a good feel for design imperfections so I don't notice when something is off) but I am saying I am generally familiar with this behavior in devs regarding other technologies, if one is sufficiently good with a technology one dislikes restraints placed on usage by some external library.

This is why people always comment "This would be so easy if we weren't using {X} technology on top of our code" because they generally are comfortable using the lower layer that the higher layer is now controlling and preventing them from doing their work in what they see as the best way to do it.

So, all that said, I would expect that if Good CSS authors were forced to use Tailwind they would not like it. The assertion to the contrary is extremely surprising and I just don't believe it without some extremely surprising proof to back it up.

Re:Tailwind vs. Semantic CSS by Timon3 on Monday October 23, 2023 @06:17AM (#37983680)
> well I haven't used Tailwind but from the examples I've seen I would hate it, and from what I can see I would hate it for the same reason that I hate all CSS abstractions I've worked with - because they limit what I can do with CSS in the interest of making it easier for other people who are not that good with CSS to get their work done OR it will require me to do things in a particular way when I believe I know a far better way of doing them.

Tailwind explicitly doesn't do this. You can do pretty much everything you'd do with normal CSS. There are a couple of edge cases where you have to add configuration (e.g. if you want specific media queries), but Tailwind doesn't limit you in any way.

I also support the assertion that good CSS authors like Tailwind.

Re:Tailwind vs. Semantic CSS by flagrant_taco on Monday October 23, 2023 @09:24AM (#37985243)
There are a few important limitations, Tailwind can't fully support logical properties for example because `mb-8` could mean margin bottom or block. Any use case that requires styling one element based on another gets a bit hairy too.

Both of these can be technically worked around. Config may be able to disable existing margin/padding classes and replace them with a custom set, and the groups feature helps especially for simple cases of referencing other elements.

In my experience though, as soon as config is meaningful modified or you elan on the more obscure features for groups, pseudo selectors, etc. the learning curve has just been moved from the dev who doesn't know CSS to the dev who doesn't know Tailwind.

Re:Tailwind vs. Semantic CSS by Timon3 on Monday October 23, 2023 @09:48AM (#37985587)
Thank you for the correction!
Re:Tailwind vs. Semantic CSS by bryanrasmussen on Tuesday October 24, 2023 @03:21AM (#37995750)
that is also a thing, when I look at tailwind, having spent my time learning CSS why would I want to learn another syntax to help me do what I can already do, and probably do better.