I suggest trying it out & reading more about it. It's the only way utility CSS frameworks like this seem to click.
In my opinion, Tailwind works best when being used to create template components. In your button case you would just modify your reusable button component or the reusable base button component if you have multiple button components.
You get the best of all worlds.
* You avoid writing a lot of CSS.
* You don't have to worry about thinking of CSS class names or name pollution
* I find it faster & easier to style components with a utility CSS framework in something like Storybook than it is with CSS.
* I recommend adding a plugin to your editor to help with the names of Tailwinds classes. VS Code has a couple that will suggest the right class name based on what you type.
Using utility classes to build a UI is much more like building something with SwiftUI, where no one seems to argue about this silly "separation of concerns" thing we talk about on the web.
I'm still not convinced — using only utility classes has very clear downsides, while using what's reasonably one of the most common approaches in the industry right now avoids those downsides while also providing additional benefits.
Yes, you probably will need to create some custom classes from time to time. Ideally those might be done in a utility fashion though.
Furthermore, styled buttons are such a common occurrence that TailwindCSS encourages users to extract common CSS patterns into component classes[0].
From a size perspective, compression takes care of the repetition pretty well. Utility classes allow for better reuse, meaning the overall page often is, in fact, lighter.
Nowadays most pages are put together using some kind of components anyway, so changes are that your button is already defined in one place. Otherwise you can extract your own button class.
Also see my reply to bbmario.
My smallish sites don't use build pipelines and post-generators and so on, I'd just like a reasonably-sized CSS file to include.
(I realize that's a niche use of those frameworks)
Oh, and if I may dream, https://caniuse.com/#feat=css-apply-rule throughout all browsers would be great!
https://tabatkins.github.io/specs/css-apply-rule/ https://www.xanthir.com/b4o00
It is similar to inline styles in how atomic it is but provides responsive classes which adapt to screen sizes.
It also provides predefined defaults for sizes and colors to prevent codebase rot and design inconsistencies.
Allows combining framework classes into nameable classes (requires using their building tool).
As someone who uses scss and know css myself I will not use it but I can see how it can be useful for devs who don’t want to learn css.
I just can’t get over the inefficiency of learning all their styles and typing them as classes feels gross compared to BEM. But I get it.
You'd often use something like a component based JS framework or a server rendered templating language, making it easy to contain all utilities with shared logic in one place.
CSS however is very much like drawing rather than engineering. Some aspects are just not scalable. You can draw many things in vector by conbining shapes for example but a pen or pencil is still very necessary for many parts of both exploratory creation as well as something polished.
The same goes for HTML and Javascript to an extent. While it’s great to build railroad tracks, you can’t take a train everywhere... any abstraction has to also have the ability to easily break out of it to handle edge cases. Clean and Pure abstractions almost never have the grittiness necessary to reflect a fractally complex problem.
1: https://developers.google.com/speed/docs/insights/OptimizeCS...
It's an interesting idea to entertain as a thought, and some utility classes certainly hold value in general, but I don't see how you would ever reasonably want to use this in a project. It has all the same drawbacks as writing inline styles on elements, not to mention the large size.
Say you have a number of views and decide (or a client decides) you want all of the buttons to have a bit more padding. If anything else happens to completely accidentally also use the same padding class you're always left with manually checking every single instance just for a small change like this.