Live data from Hacker News

Tailwind vs. Semantic CSS

nuejs.org

141–150 of 211 posts

Re: Tailwind vs. Semantic CSS

#141
post #29

Earlier quoted context omitted.

Yep ! This is the huge problem with css and «meaningful» selectors, no matter how much you try to make things clear, nuances and details fades and you end up going back end forth between css code, inspector and HTML to figure out what's happening. Utility based css selectors that do one and single thing are clear and explicit, removing most (but not all) that hassle.

Not all developers have experienced these problems. There are people who prefer the semantic approach. I'm definitely one.

Yes, there are conditions of people and project where you can avoid those.

But they a are plenty of situation when it becomes too hard, such as when you can't constraint a designer to your implementation details, or that same semantic concepts have different UI cases.

Re: Tailwind vs. Semantic CSS

#142
post #125

Earlier quoted context omitted.

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.

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.

tailwind doesn't need to know anything about your components.

Re: Tailwind vs. Semantic CSS

#143
This article makes a couple of false/misleading claims. But let me write about what it presents as a better (old) practice compared to TailwindCSS first:

“Semantic CSS” is not a standard, like semantic HTML follows certain rules that are widely accepted. At the end of the day, everyone is writing their own “button” CSS class, and it is different on every website you look at. It doesn’t help whether you name something “.nav” or “.gallery” if you are the first person deciding the CSS rules for it. Your code might be “semantic” in your personal understanding of how things should be named, but your naming convention is useless to others who have to maintain your code and still need to look up what “.gallery” actually means. So, from my understanding this is part of the reason TailwindCSS exists: transparent markup and improved maintainability in the long term.

As stated above this article makes a couple of false/misleading claims. For example:

- With TailwindCSS “you are forced to wrap divs inside divs inside divs”. Not true. I'm writing TailwindCSS code for a couple of years now and can confidently say that this is NOT what Tailwind forces you to do. You don’t need extra HTML markup to make Tailwind work. Your HTML can be perfectly “semantic” without wasted divs.

- “… utility-first approach lacks the power of CSS selectors”: Not true. TailwindCSS comes with grouping and child selector classes, for example.

- It also states that Tailwind styles elements exclusively inline, which is also not correct. They encourage you to name things as well but warn you of premature abstracting in their docs (https://tailwindcss.com/docs/reusing-styles#extracting-class...).

———-

I also can't help but feel a little patronized by the tone of this article. Examples:

- “Mastering CSS requires practice”

- “But when you truly master CSS, there is no turning back” (and you don't need Tailwind)

- You only require Tailwind when you have a “bad CSS structure” or you don't care about your code (https://nuejs.org/blog/tailwind-vs-semantic-css/#but-i-move-...).

If I was new to coding, these statements would discourage me trying out new things. I don't know how you learned to code, but sticking to the fundamentals didn't get me anywhere. Yes, you need to learn them, but you also want to get things done (and figure out later how they work). Writing CSS is not an ancient art, it’s not pretty or a noble thing to do.

Re: Tailwind vs. Semantic CSS

#144

Earlier quoted context omitted.

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…

> 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…

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

#145
Oh and by "mastering css" we just mean to learn the basic box model (width, margin, padding), units (em, rem, px, %, vh, dvh, lvh, etc.), the normal flow of each HTML element, the display basics (inline, block, contents, none, initial, revert, inherit, unset, etc.), positioning (relative, static, absolute, etc.). Flexbox and Grid deserve their own chapters. Ah there's also those capabilities for elements to float and overflow... Also, those are just the basics for positioning we didn't cover things like colors and selectors. Feel free to explore, deep dive and stay up-to date (it's moving fast) so that you can become a real css master!

Maybe it's just a mess that no sane person want to learn. Semantic html is really about creating blog posts, there's not much elements provided beyond that. If you want to create an e-commerce website for example, there is no "card", "carousel" or "popover" element. You have to make them yourself based on existing elements which then makes the css styling confusing.

Re: Tailwind vs. Semantic CSS

#146

Earlier quoted context omitted.

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.

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…

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

#147
post #137
post #38

Earlier quoted context omitted.

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…

> Rules are scoped globally. Isn't "CSS scoped to components" nowadays a basic feature of frameworks?

The author is advocating for rules like "body > header" in separate css files.

Re: Tailwind vs. Semantic CSS

#148

Earlier quoted context omitted.

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.

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)

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

#149

Oh and by "mastering css" we just mean to learn the basic box model (width, margin, padding), units (em, rem, px, %, vh, dvh, lvh, etc.), the normal flow of each HTML element, the display basics (inline, block, contents, none, initial, revert, inherit, unset, etc.), positioning (relative, static, absolute, etc.). Flexbox and Grid deserve their own chapters. Ah there's also those capabilities for elements to float and…

Yes! I strongly recommend to learn the fundamentals of web development and the basics of HTML, CSS, and JavaScript. At least if you are pursuing a career on web development. Learning CSS makes you a better Tailwind developer too.

Re: Tailwind vs. Semantic CSS

#150
post #137

Earlier quoted context omitted.

> Rules are scoped globally. Isn't "CSS scoped to components" nowadays a basic feature of frameworks?

The author is advocating for rules like "body > header" in separate css files.

Indeed! I'm a freak using CSS as intended :)
Post reply on HN