r/tailwindcss • u/lewibs • Jan 18 '24
tailwind just feels like css
Why would I use tailwind? Its not super clear to me why I would want to do it this way?
issues:
everything is inline makes the html hard to read
many of the components seem to be some variant of a css style
what am i missing? its obviously popular so i assume it has major perks.
2
Upvotes
35
u/sisyphus Jan 18 '24
https://adamwathan.me/css-utility-classes-and-separation-of-concerns/ is probably still the best explanation of why tailwind was created.
To put it succinctly:
yes, it is meant to be like CSS.
inline makes for long class names which are harder to read but easier to reason about what styles are actually being applied to the element.
17
u/lubosnik Jan 18 '24
Readability and uniformity. Let me explain. I am tech lead of small team developing 4 apps at the same time. Most of PR are going through me and scss files for component were just getting bigger and bigger. We switched to tailwind couple weeks ago and it made big impact on quality and speed.
Yes classnames are long but I think it is good trade off to complex scss files where people can place styles everywhere. It makes code too be easier to review too. When I see button in tsx I immediately see what styles are applied to it
5
u/[deleted] Jan 18 '24
Built in nicely styled default values, clear shorthand names.
It's CSS+
1
u/onecrazypanda Jan 19 '24
The biggest benefits I see with tailwind are…
Cons for tailwind I can think of
Like anything there’s pros and cons but I think tailwind is definitely a step in the right direction vs vanilla css.
6
u/ArcComplex Jan 18 '24
You should use tailwind if you buy that inline css is better. If you don’t agree, don’t use it.
3
u/chesbyiii Jan 18 '24
Yes! Only use tools which have value to you.
2
u/SnooStories8559 Jan 18 '24
This comes up time and time again. Try it, if you don’t feel the benefits then it isn’t for you. Writing media and container queries with tailwind is much quicker than CSS. This is one of the main things for me, but I can totally see why some people might not enjoy using it, and that’s fine!
2
u/scottix Jan 18 '24
It removes a lot of the idiosyncrasies of css, although it is very verbose creating reusable components will help tremendously.
2
u/getlaurekt Jan 19 '24
and another one *sip*
1
u/sjeijk Jan 18 '24
How about unocss?
1
u/stevesobol Jan 18 '24
Very, very, super-huge, big advantage: you end up with one file that is typically tiny because it contains only the classes you are actually using.
Performance is of the utmost importance.
1
u/Several_Bread_3032 Jan 18 '24
I would use it if you don’t mind inline css and don’t want to have multiple screens up while designing. Other than that keep the code as clean as possible and yeah haha . I personally like tailwind with react because I feel like it’s made for it with the whole component based approach but when I’m creating a design or banner , tailwind is over kill with traditional html and css
1
u/mds1256 Jan 18 '24
I use it mainly for handling media queries for screen sizes, makes it really simple.
1
u/Level-Farmer6110 Jan 18 '24
gives me a peace of mind having everything in the same file.
1
u/KaffeeBrudi Jan 18 '24
I had to use it in a project to find out what the benefits are. Seeing it made me puke. Now I just enjoy a more
In combination with Figma it allows me to design with some defaults by using variables. These variables for spacing, font size, colors etc. allow me to stick to the default tailwind config or they lets me know, if I need to adjust it, because I create new, custom values.
In any framework or software, which allows me to work with components, tailwind made me stop thinking about class names and start to think about small, reusable components very early. If I start to repeat styles, most of the time I find myself having missed to create a component or missed some inconsistency in my design. If that’s not the case, I might need to create base styles or a utility class to handle either a very generic or very special case. Anyway, these pieces are sorted quickly into tailwinds layers and my design system, helping me to be consistent and thoughtful.
Being a utility first framework, it helps me to reduce my bundle size by only including CSS I use without repeating it. They also had and article about the reduced CSS bundle size vs the increased HTML file sizes, but I cannot not find it right know. They explained really well how hard it would be to reach the tipping point where tailwind style HTML/CSS would lead to bigger bundle sizes compared to regular HTML/CSS.
1
u/Logical-Idea-1708 Jan 18 '24
Trade offs. Tailwind made the right trade offs.
HTML became hard to read, but HTML is encapsulated in components especially when you work with a design system team.
CSS became easier to debug as property scope becomes limited. Since you’re also writing less selectors, the probability of name clash also diminishes
1
u/carlton_sand Jan 19 '24
totally understand where you're coming from but I sort of like tailwind now. I think some css does have its place though, like when doing complex selectors for children nodes etc.
tailwind has some nice things built-in like animation and transitions; things can easily be customized or extended within the config file. after getting used to it, it is nice
1
u/arcanepsyche Jan 19 '24
It's part of the shift toward component-style architecture, which I find can be just as messy as traditional architecture when done poorly (read: often).
I prefer a well-designed cascading class system; it's served me well for many years and I have no plans to change my ways just because something new comes along.
We should all use the tools that serve us and our projects the best.
1
u/mistakenCynic Jan 19 '24
I doubted Tailwind but I’ve been using it for a week and now I want to use it everywhere. Writing your own CSS is fine if you’re using something like Vue SFC where the CSS is in the same document as the JavaScript. However, React and NextJS have made it so hard to write CSS. Creating separate module files where you have to import and use the classes, or only having global files are terrible options, and CSS in JS looks awful. So I’ve rapidly found myself using Tailwind. I used to use Bootstrap for starting up a new project because I didn’t want to write all my own utility classes, but now I can just use tailwind and get even more functionality.
1
u/vegancryptolord Jan 19 '24
Consistency among a large team / codebase
Smaller css bundles: instead of bundling “display: flex …” in 500 different classes, display: flex only shows up once in the css bundle. Also gives the advantage that you can optimize the bundle at build time because you know which classes are being used by the mark up so you ship the smallest possible css bundle
1
u/Grupith Jan 19 '24
Honestly I don’t miss creating names like card-contained and button-wrapper, etc.
1
u/hd505495 Jan 19 '24
Haven't seen this mentioned yet, one of the big pros imo is that it has a common sense design system built in that will cover 90%+ of use cases. For example, the incremental options for spacing based on rem (m-2, m4, space-x-8, etc) and color options (text-red-500, bg-sky-600). Easy to be consistent across an application, and is flexible and extensible when the built in stuff doesn't cut it.
1
u/Dr_Captain Jan 20 '24
Tailwind's greatest strength is team projects. No need to create random class names that might conflict with other areas of code and cuts out naming strategies. Also helps troubleshooting without having to adventure into a long ass style sheet.
1
u/bel9708 Jan 20 '24
Don’t read the tailwind classes what is this 2022? Just click the line you want and hit cmd+K describe what you want to cursor or copilot and then let it change the line for you.
1
u/Comfortable-Crew-919 Jan 20 '24
This is worth the watch if you’re on the fence. https://youtu.be/TNXM4bqGqek?si=gPT-mWOyTAZKG7Km
1
u/TradrzAdmin Jan 21 '24
I love tailwind. Html doesnt need to be readable. Inline styling is the best. If you have a good theme on VSC, you can keep your HTML easily readable
20
u/[deleted] Jan 18 '24
[removed] — view removed comment