News for hackers. Stuff that matters.
Re:Tailwind UI by mike1o1 on Wednesday February 26, 2020 @11:48AM (#22424685)
Tailwind has been great and I've been looking forward to this for months. I fought Tailwind as a concept pretty hard at first, but after hearing Adam and a few others raving about it I gave it a shot. It takes some getting used to at first but I can't imagine developing without it anymore.

To me, the biggest benefit of Tailwind and utility classes in general is that it removes the cognitive overheard of having to think of class names while designing a new page.

For example, if I'm working on a card and I want some text below the main text to have a smaller, gray font size. What do I name that class? "card-sub-text", "card-sub-title"? No - don't even worry about it - "text-sm text-gray-700" and move on.

Later on, if I end up repeating that combination in a number of places, I have more context of what that class name really should be, and I can extract the utility classes to a specific class name.

Really powerful stuff that has helped to increase my velocity quite a bit.

Re:Tailwind UI by tomc1985 on Wednesday February 26, 2020 @04:20PM (#22427464)
How is that any different from setting CSS in the style attribute of your tag? What happens when you need to update all the "text-sm text-gray-700" to something else?

Seems like a step backwards at worst and identical to Bootstrap/Foundation at best. Everyone provides class primitives like that

What you're describing offends separation-of-concerns

Re:Tailwind UI by graydsl on Wednesday February 26, 2020 @06:05PM (#22428449)
Tailwind user here. :)

One of the biggest benefits in my opinion is, to communicate the different utility classes to your UI/UX person. By restricting him/her to discrete values for margin, padding, colors, etc. they will not go overboard with there designs and also make the handoff way easier. If you use zeplin for example you can for example define color names in the sketch file and zeplin will show them in their UI. You just click on a text and see "ahh she used text-gray-500".

Much less friction in the workflow.

As for the concerns about messy markup mentioned in some other reply. True that can happen sometimes, but if you use React or Vue, you can encapsulate a lot in components. The markup in the components high up in the tree will look basically the same. And the leaf components should be quite small anyways.

Another really nice benefit to the old way is that you don't have to worry about breaking stuff. When you change bg-gray-200 to bg-gray-300 you can be sure that it only affects the element you have in front of you.

But in the end I think people have to try it out to be able to judge Tailwind.

Re:Tailwind UI by rawfan on Wednesday February 26, 2020 @07:12PM (#22428976)
Concerns are not separated in the first place. Your CSS is heavily tied to the structure of your HTML and you even need to artificially think up structures to be able to write and apply the CSS. I recommend reading Adams blog post on the topic.

Regarding style attribute. You can’t do responsive-ness, hover- or focus-states in style attributes.

It’s hard to compare to bootstrap and the like because they give you components, while Tailwind is just a different way of writing CSS. You can of course extract components, btw, and define stuff like text-primary (that you can change in a central variable).

Re:Tailwind UI by inopinatus on Thursday February 27, 2020 @05:37AM (#22432177)
> What happens when you need to update all the "text-sm text-gray-700" to something else

You update it in the one place (template/render function/component/helper/view/partial) that you wrote it.

> What you're describing offends separation-of-concerns

The entire HTML/HTTP/CSS/Javascript web schmozzle offends separation of concerns and is shot through with layering violations and dependence on the specific rather than on abstractions.

Tailwind responds to that particular shitshow by refactoring style at the point of HTML generation, which (particularly in a template-driven world) makes a crapload more sense than trying to build higher-order style abstractions in a language that was explicitly intended to not be Turing complete.

If the HTML ERB had chosen DSSSL instead of CSS, we wouldn't need this.

When it comes to developer productivity and happiness, composition beats inheritance, even in declarative paradigms.

Re:Tailwind UI by mike1o1 on Wednesday February 26, 2020 @04:27PM (#22427528)
Typically the "text-sm text-gray-700" would be a one-off styling while I'm developing a page or a component, not necessarily something that will be repeated a hundred times.

If it turns out that later down the line I realize that "every card should have that size and color for the card title", then I'll pull it out to a separate class or part of a partial or something like that.

The idea being at that point then I have more context around when and how that particular section of a component should be displayed, so I have more context about what I should name the class (i.e. "card-subtitle").

I feel like the documentation explains it fairly well if you're interested in reading more about it:

https://tailwindcss.com/docs/extracting-components#extractin...

Re:Tailwind UI by pests on Wednesday February 26, 2020 @05:36PM (#22428191)
My question is why you cant just name the card and then use selectors to style the title or any other internal styling?

This removes the need to name at all. It can just be .card > h2 or whatever and there you would do your font-weight and color.

Re:Tailwind UI by mike1o1 on Wednesday February 26, 2020 @05:59PM (#22428402)
Because I don't want that cognitive overhead of even thinking about what the selector should be. Then what if I have another sub-sub text? Do I make that an h3? An h4? I don't want to have to think about that. I just make it "text-xs" and move on.

I don't even need to move over to my css file at all - I stay within my template and stay within my flow.

It seems crazy and counter-intuitive at first, but I find that it makes me a lot more productive.

Re:Tailwind UI by iCarrot on Thursday February 27, 2020 @01:12AM (#22431007)
Something to consider: semantic HTML helps with accessibility.
Re:Tailwind UI by strokirk on Thursday February 27, 2020 @03:24AM (#22431616)
Yes, but class names doesn't affect the semantics of their tags.
Re:Tailwind UI by danzig13 on Thursday February 27, 2020 @06:30PM (#22439083)
Have to agree. Having to think about the selector makes you think about the structure and make things more semantic.

I have been paralyzed by trying to do things the semantic way before too though. And now no one cares according the markup I venture to look at now and then.

Re:Tailwind UI by pests on Thursday February 27, 2020 @02:48AM (#22431473)
I understand but then why not .card > *:nth-child(1) and then so on down the child list? You could get away with those two selectors to match anything with at least an initial name. No decisions except for the first name.

Some editors like Brackets allows you to edit other files online and handles css specially so you can edit it just by hovering over class names, etc.

Re:Tailwind UI by losvedir on Thursday February 27, 2020 @09:23AM (#22433480)
This sounds very brittle. What if you want to come back in the future and add another section to the component?
Re:Tailwind UI by leviathan on Wednesday February 26, 2020 @10:52PM (#22430278)
Re:Tailwind UI by tomtheelder on Wednesday February 26, 2020 @05:31PM (#22428146)
It's different because it's not actually setting a specific style, it's still a semantic description. You would never need to update all the "text-sm text-gray-700" in your project to something else, that just wouldn't make any sense. You might change what "text-sm" and "text-gray-700" (I'd probably go with a more meaningful name for colors, "text-gray-primary" or whatever, but hey) actually do, but you wouldn't want to actually modify all of those to be new classes at once.

In fact, I think this scheme is a whole lot closer to what most developers actually want, which is to have composable classes that actually represent something semantic. "text-sm" is your small text. That should be consistent around your application. If you change what some of that looks like, you probably ought to be changing all of it. If you want a few elements to use a different text size, then go change the classes on those.

I really encourage you to try this out. I was somewhat skeptical, but it truly feels like a huge step forward. Going back to something like Bootstrap/Foundation or- God forbid- BEM feels incredibly painful to me now.

I also don't think separation-of-concerns is a reasonable goal. I read this article [1] after using tailwind for a while, and I agree with almost the entirety of it.

[1] https://adamwathan.me/css-utility-classes-and-separation-of-...

Re:Tailwind UI by ivanhoe on Wednesday February 26, 2020 @05:59PM (#22428399)
Classic question is what happens if you decide to change all gray text with the blue one? Do you end up having the class named text-gray that is setting text to blue, or you search & replace class names...
Re:Tailwind UI by graydsl on Wednesday February 26, 2020 @06:07PM (#22428470)
IMHO search & replace would be the way to go here. Otherwise no one will understand it later on.

But you could also define a color called text-primary, if you are concerned that something like this would happen.

Re:Tailwind UI by neovive on Wednesday February 26, 2020 @08:23PM (#22429450)
I was turned off to Tailwind at first, but after watching the screencasts[1] the workflow started to make sense. I personally find writing good CSS/Sass from scratch very tedious. For something as "simple" as styling, there are many decisions to make regarding naming conventions, modularization/file structure, specificity, design systems, etc. I almost always opt for pre-built frameworks like Bootstrap or Bulma, but as my projects grew in size, I find myself battling with the framework to customize the components.

I don't think Tailwind is perfect, but find the benefits of consistent naming, easy modifications, and the "instant" design system, more than outweighs the negatives of utility classes. The framework also feels very light since there's no need to preprocess potentially hundreds of Sass files and I can just modify the view template or component directly. PurgeCSS also works amazingly well with Tailwind.

Adam, Jonathan, and Steve are also generous contributors to the opensource community!

[1] https://tailwindcss.com/screencasts/

Re:Tailwind UI by manigandham on Wednesday February 26, 2020 @08:05PM (#22429350)
Reality is more important than technical purity. CSS styles and HTML structure are not separate concerns but tightly integrated in most projects.

Using Tailwind (or other atomic css frameworks) makes it easy to reason about styling while staying completely inside HTML during editing. Within a few days, you quickly memorize all the names and can build complex visuals while also benefiting from the well-designed default sizes and options.

Re:Tailwind UI by meigwilym on Thursday February 27, 2020 @05:27AM (#22432135)
I completely agree with you.

My approach is to use class names, and in a custom stylesheet use tailwind's @apply function, so

.page-section { @apply bg-white rounded shadow overflow-hidden max-w-lg; }

Re:Tailwind UI by arcatek on Wednesday February 26, 2020 @11:53AM (#22424756)
Disclaimer: I haven't used Tailwind. Maybe I'm missing something.

> For example, if I'm working on a card and I want some text below the main text to have a smaller, gray font size. What do I name that class? "card-sub-text", "card-sub-title"? No - don't even worry about it - "text-sm text-gray-700" and move on.

What's the difference with "color: gray; font-weight: 700"? In this case I really don't have to care about the property order, whereas in your case I would guess you still have the cognitive overhead requiring you to know that "gray" comes before "700" (unless it's expected to be preprocessed away? what if I use text-700-gray?).

Re:Tailwind UI by mike1o1 on Wednesday February 26, 2020 @11:59AM (#22424824)
"text-sm" is just font-size and text-gray is a color code, so the order of the classes doesn't matter either.

The biggest benefit of this over inline styles is that if I decide to change the color of "gray-700", since those colors come from a configuration, I only need to change it in my configuration.

It takes some getting used to of the rules, but after a day or two I don't even need to think about what the class names are.

Re:Tailwind UI by squeaky-clean on Wednesday February 26, 2020 @12:47PM (#22425327)
(Also not a Tailwind user) I guess the common response to this is that well chosen semantic names usually help later down the line after these kinds of changes happen, especially with devs coming in and out.

I've actually come across C code that had "#define ONE_THOUSAND_TWENTY_FOUR 4096" because that was the audio buffer size and later had to be increased to 4096 but the macro name was never changed. AUDIO_BUFFER_SIZE would probably have been a better name in the first place.

Most code is not that bad though, haha. But that is still my first reaction. What if instead of slightly changing the gray color, you now want them to be blue and underlined? Or take HN for example, the username, vote buttons, and timestamp are all #828282, but have different class names. Is keeping this in sync ever a problem in Tailwind? This is only my first time looking at Tailwind, but it seems it's not really meant for "complex" apps where you'd run into these problems often?

Re:Tailwind UI by mike1o1 on Wednesday February 26, 2020 @12:56PM (#22425431)
If I wanted to change all links from gray to blue/underlined, the best practice there would probably be to use a different utility class (text-blue-500 and underline) and update my templates/partials/whatever.

I think for your specific example, I would use the `@apply` directive to apply certain utilities to all links.

I've used Tailwind on large, complex apps with around 50 screens (so far), and using extracted components or partials hasn't been a problem at all with keeping things in sync.

``` a { @apply text-gray-700; }

// now becomes a { @apply text-blue-500 underline; } ```

The documentation goes over this pretty well, I think.

https://tailwindcss.com/docs/extracting-components#extractin...

Re:Tailwind UI by saagarjha on Thursday February 27, 2020 @06:02AM (#22432269)
What if I had two types of links, both of which were currently "text-blue-500 and underline" but I wanted to make one italics at some time in the future?
Re:Tailwind UI by blattimwind on Wednesday February 26, 2020 @12:33PM (#22425162)
> The biggest benefit of this over inline styles is that if I decide to change the color of "gray-700", since those colors come from a configuration, I only need to change it in my configuration.

But gray-700 says it's a 70 % gray. Changing it to something else is akin to changing "color: #666" to "color: #444" through redefinition (JS?).

Re:Tailwind UI by mike1o1 on Wednesday February 26, 2020 @12:41PM (#22425255)
No, "gray-700" doesn't mean it's 70% gray. The term "700" is just referring to a color on a scale. I don't even need to name it "700", I can name it "dark" or whatever I want (which is what previous versions of Tailwind used).

i.e. "text-gray-dark", or "text-gray-700", would have a class with a single css property:

color: #4A5568;

By default Tailwind comes with a default color palette with hand picked colors. They were hand picked by a designer, not determined through an algorithm.

https://tailwindcss.com/docs/customizing-colors#default-colo...

Re:Tailwind UI by stanmancan on Wednesday February 26, 2020 @02:11PM (#22426165)
The numbering name system makes it really easy to make incremental changes too. I can’t manually edit a hex to my liking, but I can easily change text-blue-500 to text-blue-600 if I want it a bit darker.
Re:Tailwind UI by 6510 on Wednesday February 26, 2020 @04:16PM (#22427406)
#000000 is black

#FFFFFF is white

They are 3 sets of 2 hex numbers.

#FF0000 is red

#00FF00 is green

#0000FF is blue

(you hear of RGB, Red Green Blue, in that order)

Now if you want a darker color (closer to black) you lower FF to a lower value. A darker blue would for example be #0000AA

if you want a lighter color you increase the other 2 color values. A lighter blue would be #2222FF

If you don't like hex there is rgb(0,0,255) which does exactly the same.

There is also rgba(0,0,255,0-1) with an alpha channel.

You can also put any part of that in a css variable and use it where you like.

body{--foo: 0,0,255,0.5; bar:0,0,100 }

p {background: rgba(var(--foo)) }

div {background: rgba(var(--bar), 0.8) }

Re:Tailwind UI by mike1o1 on Wednesday February 26, 2020 @04:29PM (#22427550)
Sure, but the colors from Tailwind aren't determined through an algorithm like this. They are handpicked from a designer, which I feel like most design systems do as well.
Re:Tailwind UI by dsego on Wednesday February 26, 2020 @06:45PM (#22428789)
RGB isn't even a good system to lighten or darken colors. CSS supports HSL which is certainly more intuitive. Then again, it's easier to use a good pre-processor with color functions to darken($color, 10%) and so on (quickly, can you tell me what is 10% lighter than 2222FF off the top of your head?). Still, in the end it makes most sense to use tones from a good color palette then to mess around with hex values.
Re:Tailwind UI by legostormtroopr on Wednesday February 26, 2020 @04:34PM (#22427596)
> I decide to change the color of "gray-700", since those colors come from a configuration, I only need to change it in my configuration.

This sounds like a boldRedText pattern to me [1]. I get the idea of adding utility classes that inherit the base classes, but altering the definition of the "gray" class to be some other color feels wrong.

[1] http://thecodelesscode.com/case/95

Re:Tailwind UI by dwild on Wednesday February 26, 2020 @05:02PM (#22427846)
gray-700 isn't really 70% gray though, it's a darker gray than gray-600 and a lighter gray than gray-800. It also contains a bit more blue in it, which is actually quite common to do with gray.

In reality I'm pretty sure that you wouldn't alter it directly either and that if you do, you would try to keep the 10 versions of it somewhat linear, or at least consistent with the use that you do of it. Theses colors are there for prototyping quickly yet still offering good looking result. Sure "color: gray" works, but look at the colors choices [1], it's much better than the default gray and offer more choice than lightgray, gray and darkgray without having to do math over #808080.

[1] https://tailwindcss.com/docs/customizing-colors/#default-col...

Re:Tailwind UI by jaf656s on Wednesday February 26, 2020 @12:45PM (#22425292)
I have been using tailwind on a new project and I only see 3 real benefits over using inline css styles:

1) Sizes are standardized in a predetermined set of discrete size classes. So you start to think about sizes, padding, margins, etc in terms of steps instead of values. You can change the steps in one place and they apply globally. It's a little easier to standardize a rough style guide compared to starting from scratch.

2) Colors are standardized in a similar way. You just need to configure your app's core colors and then you can just think in terms of steps instead of color values.

3) You have a smaller set of "best practice" means to achieve most outcomes compared to all that's available with css. You don't need to know the best way to do what you want, you can just browse the documentation to find what you want.

Outside of that, you still have to use @apply to collapse utility classes into more semantic classes if you want style changes to cascade (tailwind recommends using components or view partials to achieve this instead of via css classes, though this would work equally well with inline styles)

The styles are very verbose, just like with inline styles. They are only slightly shorter than inline styles since they are basically abbreviated forms of inline styles.

You can still do everything tailwind does for you by using your own style guide and building out css classes, but tailwind gives you a head start.

It feels like it makes you more productive in the beginning because you get a toolset with a lot of decisions already made for you, but I suspect it will make things a bit slower as the app gets more complicated.

Re:Tailwind UI by stefanfisk on Thursday February 27, 2020 @12:09AM (#22430688)
I big benefit is that Tailwind supports media queries, while inline styles can't help you at all there.
Re:Tailwind UI by jaf656s on Thursday February 27, 2020 @11:23AM (#22434599)
oh yeah, I forgot about media queries. Which is impossible inline, but also adds to the verbosity
Re:Tailwind UI by dwild on Wednesday February 26, 2020 @04:55PM (#22427790)
Someone else mentioned this and as I'm not a Tailwind user either, it made me understood a bit more the principle.

text-gray-700 is not a font-weight, it's a color predetermined by the framework. They aren't generated, they are hand picked by a designer. Each addition of 100 is a bit darker.

https://tailwindcss.com/docs/customizing-colors/#default-col...

So essentially, what's the difference between style="color: gray;" and class="text-gray-500" is mostly that you get a more beautiful gray (they add a bit of blue in it).

I guess "text-sm" is also similar, with an hand picked size which appear nice on every device and can be considered "small text".

Re:Tailwind UI by jhardy54 on Wednesday February 26, 2020 @05:25PM (#22428080)
In that case, isn't that basically style="color: var(--gray-500);" with extra steps? I love to see people experiment for the sake of experimentation, but I'd be hesitant to adopt Tailwind as an engineer unless I understood why they weren't just CSS variables.
Re:Tailwind UI by mike1o1 on Wednesday February 26, 2020 @06:06PM (#22428458)
They are variables in that they're specified in your Tailwind configuration file, which is what generates the utility classes that are generated. If you really wanted to you, you can extract it out as a variable if you wanted to use that color elsewhere, such as part of a box-shadow or background color or something like that.

  .custom-bg-color {
    background-color: theme('colors.gray.500');
  }
Re:Tailwind UI by dwild on Thursday February 27, 2020 @10:23AM (#22434026)
CSS variables are still relatively new though, unsupported until about March 2018 in all browsers, yet the first commit over TailwindCSS is from Jul 20, 2017, nearly a year before browsers even supported the feature. Even today it seems like 11% of users doesn't have support for variables. Could make sense to add support for variables now, but for the sake of backward compatibility, it does make sense to keep it with classnames too.

I love though that as an engineer you would be hesitant to use Tailwind, but you are not aware of how new variables are.

I think Tailwind seems to make sense for any prototypes works and probably even an MVP for a company that still doesn't have a shared CSS that represent the style of the company.

Re:Tailwind UI by jhardy54 on Saturday February 29, 2020 @02:30PM (#22452465)
My point isn't that Tailwind should've used CSS variables in 2017, it's that technology from 2017 isn't very compelling in 2020.

> I love though that as an engineer you would be hesitant to use Tailwind, but you are not aware of how new variables are.

Why would you think I'm unaware? Please see: https://caniuse.com/#feat=css-variables

I'm not writing software for IE 11 (released in 2013), Opera Mini, QQ, or Baidu, so CSS variables are widely supported for my target demographic.

Re:Tailwind UI by whelming_wave on Wednesday February 26, 2020 @05:30PM (#22428131)
For plain old `text-gray-500`, they're pretty similar. One advantage that Tailwind has is screen sizes - you might write `flex items-center justify-between mobile:flex-col` for a row that turns into a column on smaller screens where the UI becomes awkward, for example.
Re:Tailwind UI by zupa-hu on Wednesday February 26, 2020 @05:07PM (#22427893)
I think the key difference is that you can't use conditionals in style attributes. For example responsive variants, hover, focus, etc.

`text-sm lg:text-lg` is something you simply can't do in style attributes.

`text-gray-700` or `color: var(--mycolor-gray);` is indeed not _that_ much different. (I'm using CSS variables here to achieve the same as Tailwind variables.)

Re:Tailwind UI by cageface on Wednesday February 26, 2020 @06:20PM (#22428582)
Tailwind also gives you responsive prefixes so if you need different padding on mobile vs desktop it's easy to just use a lg:p-4, for example. You can't do this inline styles.
Re:Tailwind UI by rymate1234 on Wednesday February 26, 2020 @12:31PM (#22425146)
the 700 is a shade of gray not a font weight
Re:Tailwind UI by aschismatic on Thursday February 27, 2020 @12:02PM (#22435119)
I first took a look at Tailwind CSS a year ago and liked it. However, when I started using its flexbox classes I noticed it was missing one for align-content: space-between (or space-evenly, I can't recall precisely). Thankfully it looks as though those utility classes have since been added [0], however, at the time it made me hesitant to adopt Tailwind because it made me wonder how many other basic property-value pairs were not yet implemented as classes. Maybe that's a stupid reason to have given up on it, but it's just how I felt at that point in time. Do you feel Tailwind has mostly improved with since you started using it?

[0] https://tailwindcss.com/docs/align-content