Most active commenters
  • omnimus(3)

←back to thread

304 points ulrischa | 29 comments | | HN request time: 1.24s | source | bottom
Show context
ricardobeat ◴[] No.44689124[source]

    <el-dialog-panel class="mx-auto block max-w-3xl transform overflow-hidden rounded-xl bg-white shadow-2xl ring-1 ring-black/5 transition-all group-data-closed/dialog:scale-95 group-data-closed/dialog:opacity-0 group-data-enter/dialog:duration-300 group-data-enter/dialog:ease-out group-data-leave/dialog:duration-200 group-data-leave/dialog:ease-in">
Lovely. Verbosity aside, now on top of knowing CSS you need to learn another hierarchical system within class names.
replies(14): >>44689142 #>>44689193 #>>44689633 #>>44690309 #>>44690466 #>>44690969 #>>44691000 #>>44691208 #>>44691531 #>>44692110 #>>44692147 #>>44692803 #>>44694185 #>>44700048 #
1. AstroBen ◴[] No.44691000[source]
I just can't fathom how someone can look at this and think "yeahhhh thats some good clean code". How did tailwind get so popular? Learn plain CSS. It's really good now
replies(11): >>44691157 #>>44691381 #>>44691597 #>>44692249 #>>44692347 #>>44692490 #>>44692896 #>>44693989 #>>44694828 #>>44695704 #>>44697630 #
2. Jaygles ◴[] No.44691157[source]
I've worked in many different FE codebases with a variety of CSS "strategies".

This sort of thing is objectively ugly and takes a minute to learn. The advantages of this approach I found is two-fold

1. You can be more confident that the changes you are making apply to only the elements you are interested in changing

You are modifying an element directly. Contrast with modifying some class that could be on any number of elements

2. You can change things around quite quickly

Once you're well familiar with your toolset, you know what to reach for to quickly reach a desired end state

replies(5): >>44691271 #>>44691311 #>>44691864 #>>44692944 #>>44693383 #
3. iambateman ◴[] No.44691271[source]
Agree, and to add…the “component” still needs to exist somewhere in the system for tailwind to make sense.

No one is writing a long paragraph of styles for _every_ button in their app.

replies(2): >>44691650 #>>44692197 #
4. AstroBen ◴[] No.44691311[source]
This is one of the least elegant ways to scope CSS though.. you may as well just write inline CSS

I like BEM personally. "navbar__item" scopes the styling to the nav item

> Once you're well familiar with your toolset, you know what to reach for to quickly reach a desired end state

This also applies to plain CSS, doesn't it?

The big value add that Tailwind brought isn't their utility classes IMO - it's their philosophy around having a design system of consistent coloring and spacing. I actually borrowed that for my own projects. It taught me to be a lot more diligent about specifying the system upfront. Put it in CSS variables and re-use those

replies(1): >>44692314 #
5. pjmlp ◴[] No.44691381[source]
No idea, thankfully I am doing mostly backend and devops stuff, so I don't need to care.

If I do something myself, I keep using bootstrap, as it is good compromise for those of us not honoured with CSS mastery.

Ironically I have no issues making great looking UIs with native toolkit.

In 5 years the tailwind craziness will be replaced by the next shiny CSS of the month.

6. har777 ◴[] No.44691597[source]
I like how tailwind provides scoping automatically. But in projects already having a build system I use css modules. Writing pure CSS is so much nicer but please don't make me manage class names myself.
7. nojs ◴[] No.44691650{3}[source]
> No one is writing a long paragraph of styles for _every_ button in their app.

Very much not true. LLMs love doing this!

8. eviks ◴[] No.44691864[source]
1. Aren't there good tools that can list all the elements a style would be applied to so that you can pick and change only the ones affecting the element you need?
9. yxhuvud ◴[] No.44692197{3}[source]
Yes, many most definitely do just that.
10. input_sh ◴[] No.44692249[source]
Can I copy some random HTML+CSS snippet from the internet and be sure that it'll look exactly the same in my project and that no existing CSS is going to overwrite it?

I'm never gonna argue learning proper CSS wouldn't be better, but Tailwind is by far the path of least resistance for someone that has no interest in writing frontend for a living. It's like putting legos together, it requires very little thought to get from nothing to a decently looking website.

11. omnimus ◴[] No.44692314{3}[source]
You can’t use inline css it’s not at all the same.

Inline css

1. Can’t use media queries (responsive design).

2. Gets you to specificity hell - you loose ability to cascade.

3. Does not follow any system or reuse of values.

4. Values can’t be centrally changed. Utility clases are still classes - when you change class value it changes everywhere where the class is used.

5. Its verbose. Utility classes can have multiple css rules.

Conceptually it might seem that inline css is similar but thats just feeling. Functional css (utility classes) are about composing classes with simpler (one purpose) behaviour together to create complex behaviour.

replies(1): >>44692901 #
12. pjmlp ◴[] No.44692347[source]
Fashion driven development, and magpie developer references come to mind.
13. omnimus ◴[] No.44692490[source]
Tailwind goes into crazy extreme so people can copy paste whole complex components and they work. That’s why you can dunk on these verbose examples.

This is not how custom functional css codebase looks. In custom projects you change the system/configuration to fit the project. You create your own utilities for example you wont have “text-lg sm:text-xl font-semibold tracking-tight” but will have class “font-heading-2”. Similarly you will create button/input classes that have you basic styles.

Generally you start with just simple utility classes inside html and go from there and where it make sense or its too complex you separate to more complex class. You end up with short css file that only has these special components and none of the basic stuff.

For most elemets it ends up like “flex justify-center gap-4”. In BEM i have to invent “nav-secondary__header” put it in correct place and hate myself when i need to change it to “flex justify-beween”.

Tailwind popularised functional css but is also aimed at masses/noobs. Somehow some of those concepts also resonated with some experienced users.

replies(2): >>44693309 #>>44696029 #
14. troupo ◴[] No.44692896[source]
This is objectively good clean code when you develop it.

Because most of those classes are per component.

If you have a single card component defined with these classes, and then repeat it 20 times on the page, then of course the output will look like a giant mess.

> How did tailwind get so popular?

- quick to understand and get started with

- much cleaner for components than the variety of CSS-in-JS libs

- (mostly) do not require fighting CSS with BEM-style atrocities

- come with nice default styles and colors that can be easily changed and extended

> Learn plain CSS. It's really good now

CSS is okay now. We only just got nesting and scoping

15. troupo ◴[] No.44692901{4}[source]
> Values can’t be centrally changed.

Or you end up redefining dozens of CSS variables inline :)

16. Levitating ◴[] No.44692944[source]
Why not just use the style attribute?
replies(1): >>44693219 #
17. owebmaster ◴[] No.44693219{3}[source]
verbosity. Using style, "p-4" becomes padding: calc(var(--spacing)*4);
18. ricardobeat ◴[] No.44693309[source]
> will have class “font-heading-2”

At that point, why not write these in CSS instead? There is little advantage in using the tailwind shorthand classes in your own class definitions.

- You can use plain CSS variables for theming

- You're bringing back the supposed downsides of cascading and shared classes

- simple Gzip compression will achieve similar size reduction as the utility classes

Working on your codebase now requires full knowledge of the Tailwind utilities, layers, directives, pseudo-classes, theming, and all the complexity that comes along with them.

replies(2): >>44693689 #>>44693761 #
19. elktown ◴[] No.44693383[source]
When people complain about CSS being hard I'm not sure what parts of it really? It's rarely explained further too.

As someone that did a lot of CSS like 15 years ago when fullstack was the norm, then just sporadically for various non-public tooling, is that yes, the old ways of trying to position things really sucked and had a lot of hacks and some of those trail-n-error "how-does-this-change-the-elements-position" seems to still apply, but are much rarer now with grids/flex etc. But the structure of CSS itself is very straight-forward to me and has almost always been?

Is what's really going on that when people are trying to use vanilla CSS they go overboard with keeping CSS DRY? Which ofc ends up with an interdependent mess that's becomes increasingly harder to change. Just stop that? Start namespacing and copy pasting? CSS doesn't need to be compact.

replies(1): >>44699764 #
20. doytch ◴[] No.44693689{3}[source]
You’re right - if you only used it for ‘font-heading-2’, you wouldn’t need it.

But like the person you’re responding to said, the ergonomics improve for the majority of cases that are just ‘flex items-center gap-2’.

And yes, you could write it all yourself but Tailwind is a good set of defaults for those classes and minimizes bike-shedding and improves consistency. These are useful things in lots of teams.

I don’t really use Tailwind on smaller personal projects because I love CSS, but in an org of mixed skill levels, it’s pretty damn useful.

(Also, Tailwind uses CSS variables. It had solid support for them in the last major and first class support for it in the current one.)

21. omnimus ◴[] No.44693761{3}[source]
I was unclear. Yes of course you write these classes “font-heading-2” in CSS. Tailwind is essentialy big list of premade classes to dynamically pull from. I think the functional approach/structure is the interesting part why people like Tailwind. On very small projects i even make “Tailwind by hand” creating those utilites as i go.

> There is little advantage in using the tailwind shorthand classes in your own class definitions.

There are few massive advantages. I dont have to figure out how to name these classes. Other people in the team know them too. And when they see class they dont know they know its something custom probably for a reason.

> You're bringing back the supposed downsides of cascading and shared classes

I never said cascade is bad. Creating new flat class with 0-1-0 specificity doesn’t break Tailwind. I’ve been through enough of - everything has specific class that’s nested/scoped… from my experience and usecase it’s harder for little benefit except neater html.

> simple Gzip compression will achieve similar size reduction as the utility classes

I meant custom css that you write by hand and have to scroll trough. Not the result pushed to browser. With functional css you manage to do most of the work in html and what doesn’t make sense you can do traditionaly. For example i dont like doing complex hover interactions in Tailwind so the html has all the layout utilities but also custom class that only has this custom interaction behaviour.

> Working on your codebase now requires full knowledge of the Tailwind utilities, layers, directives, pseudo-classes, theming, and all the complexity that comes along with them.

Is knowing Tailwind naming conventions worse than not having any convention at all? My experience is that Tailwind are just classes that are documented. Without it we would have classes that are undocumented.

There are cases where functional css is not that beneficial. Like in long running products which have single file component workflow where css is scoped and html/css live in same file. But in work i do in small team we just found it to solve many our painpoints.

22. jtickle ◴[] No.44693989[source]
I have seen this sentiment on HN a lot recently. Any good resources for that? I was quite the accomplished web developer 15-20 years ago and want to catch up without having to learn a new library or framework every six months.
replies(1): >>44694097 #
23. smac__ ◴[] No.44694097[source]
https://www.manning.com/books/css-in-depth is an excellent option. This book helped fill in the gaps for me when it comes to modern CSS.
24. phartenfeller ◴[] No.44694828[source]
It is not the nicest but you will quickly get used to it and productive. However maintaining huge websites with thousands of thousands of lines of custom CSS will never be easy. And especially if somebody else wrote it.
25. const_cast ◴[] No.44695704[source]
Code doesn't necessarily need to be clean. We've had, like, two decades of "do clean code" and a lot of the time that mentality is shit. Putting stuff in a separate file and introducing layers and layers of abstractions to keep things "clean" doesn't always make it so. Often, it makes the code more complex, and makes behavior difficult to reason about.

The big problem with Vanilla CSS is that's it's sort of like Perl. It's a read-only language in practice.

Yes, theoretically, you can have perfect semantic CSS classes and use those. In practice, not every button is the same and you'll need slightly different styling in different places.

Yes, we could go in and change the .button class. But who is using the .button class? Where is it used? Nobody knows, and you can't find out. So editing that class is EXTREMELY risky. I have seen many an entire application break because some dev decided to edit CSS. The bigger the application, the bigger the risk.

Where I work, we have 1500 devs. Does anyone know the complete set of usecases a CSS class would have? No. Even if I gave you a month to research it, you would not find out. So you cannot edit CSS classes, it's far too risky.

So, the result is that everyone just tacks on to the end of the CSS. And now, in your clean code world, you have 50 different button classes. Um... whoops.

If you want to compartmentalize, what you can do is use components, in whatever backend/frontend framework you have. You can have the component have their own state and allow users of the component to change parts of it. Then, it doesn't matter how "unclean" the tailwind is - because you'll almost never see it. But if you need to change it, you can, without destroying the entire application. No more 50 button classes, and no more read-only implementations.

26. adabyron ◴[] No.44696029[source]
As an older dev, I think it's a great natural evolution.

We had css, then SASS/LESS/etc, now Tailwind.

In the days of just CSS people would create variables/functions for their CSS in their server side language & have the server side language create the CSS. SASS/LESS allowed us to do that in stylesheets.

Now we have Tailwind (and of course CSS variables). Tailwind (and the code editor plugin devs) have done an amazing job at making a great workflow to handle CSS, especially in component type UI designs.

* Shout out to Foundation and Bootstrap for also helping us get to where we are today. Foundation is underrated in the history.

27. Rapzid ◴[] No.44697630[source]
I was a Tailwind skeptic for a long time but I've used it on a few projects now at my full discretion.

However I use it in a much more blended way than the authors probably prefer. I use it with Tailwind Variants and to quickly hack out components. However depending on the project, component, and etc I may also construct BEM-based CSS files to live along side the component.. I use "@apply" in the CSS files, something the author(s?) are on record saying they regret. However I'd counter them by saying if it weren't for "@apply" Tailwind wouldn't be where it is today..

28. sensanaty ◴[] No.44699764{3}[source]
The hard part isn't just placing the correct styles, that is trivially learnable, it comes in when you have multiple people touching the same code, or even in small teams with a large enough project. In a large enough project, and IME that "large enough" point gets hit very quickly, things become messy and it becomes difficult to figure out why something is rendering in the way it is.

Every non-tailwind project I've ever worked on inevitably devolved into a mess where you have 50 billion CSS files scattered all over the place, many containing classes that contradict and override other existing classes, often in completely unclear ways as it's hard to know in which order things will get compiled ultimately. As time passes, you'll see BEM done in various ways, you'll see cursed SCSS functions that generate styles dynamicslly, you'll see a bunch of !importants, and eventually you end up in a state where making a change to a legacy page becomes an exercise in dodging specificity and ordering minefields.

Meanwhile with Tailwind, everything is localized to the element it's affecting, and very importantly the entire team has a "standard library" of properties and patterns they can pull from, so you don't end up with people in different teams naming similar UI patterns differently, and you straight up never have to think of specificity ever again (which in my view is a boon, despite what CSS purists might say). Yes, the HTML is more verbose, but this is just such a non-issue after the first 5 minutes of discomfort, plus all the other benefits.

Hot take, but the Cascading part of CSS has proven itself to be a massive drawback, and not a benefit. Tailwind obviates that completely.

replies(1): >>44700001 #
29. elktown ◴[] No.44700001{4}[source]
This sounds like it agrees with my point of going overboard with DRY? But this is true for pretty much all languages. When people go overboard with abstractions it usually ends up bad over time and changes, as in your example as well, starts becoming a dredge. But this is solved by experience and better practices, not throwing out the baby with the bath water. Tailwind seems strangely defeatist to me - going from one extreme to another.