TE
TechEcho
Home24h TopNewestBestAskShowJobs
GitHubTwitter
Home

TechEcho

A tech news platform built with Next.js, providing global tech news and discussions.

GitHubTwitter

Home

HomeNewestBestAskShowJobs

Resources

HackerNews APIOriginal HackerNewsNext.js

© 2025 TechEcho. All rights reserved.

Don't use Tailwind for a design system (2021)

153 pointsby redbar0nover 2 years ago

28 comments

satvikpendemover 2 years ago
I&#x27;ve used Tailwind extensively at previous companies and inevitably each one creates an abstraction that&#x27;s akin to:<p><pre><code> const headerClasses = [(list of Tailwind classes here)]; &lt;header className={...headerClasses}&gt;...&lt;&#x2F;header&gt; </code></pre> because the complexity of reading and writing all of the classes is just too much. At that point, you&#x27;ve just reinvented CSS classes. Tailwind fans will tell you to not do this but if multiple companies are independently having the same problem and coming up with the same solution, the onus is not on the user anymore, it&#x27;s on the creator to fix it. @apply can work but again it&#x27;s really not recommended by Tailwind itself, for whatever reason.<p>These days I recommend learning CSS really well and then using Vanilla Extract (<a href="https:&#x2F;&#x2F;vanilla-extract.style" rel="nofollow">https:&#x2F;&#x2F;vanilla-extract.style</a>), a CSS in TypeScript library that compiles down to raw CSS, basically using TS as your preprocessor instead of SCSS. For dynamic styles, they have an optional small runtime.<p>They have a Stitches-like API called Recipes that&#x27;s phenomenal as well, especially for design systems, you can define your variants and what CSS needs to be applied for each one, so you can map your design components 1-to-1 with your code:<p>import { recipe } from &#x27;@vanilla-extract&#x2F;recipes&#x27;;<p>export const button = recipe({ base: { borderRadius: 6 },<p><pre><code> variants: { color: { neutral: { background: &#x27;whitesmoke&#x27; }, brand: { background: &#x27;blueviolet&#x27; }, accent: { background: &#x27;slateblue&#x27; } }, size: { small: { padding: 12 }, medium: { padding: 16 }, large: { padding: 24 } }, rounded: { true: { borderRadius: 999 } } }, &#x2F;&#x2F; Applied when multiple variants are set at once compoundVariants: [ { variants: { color: &#x27;neutral&#x27;, size: &#x27;large&#x27; }, style: { background: &#x27;ghostwhite&#x27; } } ], defaultVariants: { color: &#x27;accent&#x27;, size: &#x27;medium&#x27; }</code></pre> });<p>Impressive that OP still is using ReasonReact, I thought it was all but dead after ReScript.
评论 #34337067 未加载
评论 #34337150 未加载
评论 #34337601 未加载
评论 #34343488 未加载
评论 #34338088 未加载
评论 #34337299 未加载
评论 #34337641 未加载
评论 #34336894 未加载
dubcanadaover 2 years ago
This should be called &quot;Don&#x27;t use Tailwind in a React library for a design system&quot; as this really has nothing to do with Tailwind and is all about integration of Tailwind into a React design system.<p>None of these &quot;negatives&quot; are &quot;negatives&quot; for using it as part of a standard HTML&#x2F;CSS website outside of React. The comparison between readability of a bunch of divs and web components or react makes no sense, of course &lt;SidebarItem &#x2F;&gt; is easier to read then &lt;div class=&quot;flex-1 bg-blue font-bold, text-md d:none&quot;&gt;&lt;&#x2F;div&gt; but nobody writes React like that. Everyone will have a SidebarItem component that spits out that div.
评论 #34338395 未加载
评论 #34337982 未加载
评论 #34338182 未加载
评论 #34338314 未加载
评论 #34338560 未加载
评论 #34339545 未加载
manxmanover 2 years ago
Is it just me or has the underlying purpose and value of “cascading” in CSS been lost within these abstractions.<p>The only real limitations with CSS imho was just lack of variable support for easily passing in variables to set color schemes and&#x2F;or dimensions etc.<p>These seemed to be readily fixed with SCSS and the various options for embedding CSS in JS using styled components and the like.<p>Tailwind seems to be all about making it easy to “pixel f*k” your way to getting the design you want in one given place at the expense of having consistency and maintainability.<p>E.g. with a proper CSS template I can ensure all fonts and sizes and colors are consistent across an app. With Tailwind everything starts to be like the 1990s where all your design was hard coded into table and font elements mixed into your markup!<p>This does NOT seem like progress!
评论 #34338159 未加载
评论 #34337890 未加载
评论 #34337889 未加载
评论 #34337838 未加载
评论 #34341823 未加载
评论 #34337886 未加载
评论 #34337810 未加载
评论 #34337907 未加载
评论 #34337892 未加载
评论 #34338114 未加载
评论 #34339061 未加载
dimitrisnlover 2 years ago
I&#x27;ve been using Tailwind for my component library and I don&#x27;t agree. For example &quot;It is optimised for writing, but not for reading&quot; is certainly a problem, but this is why I created a component library. To abstract this.<p>Also this is weird:<p>``` const Card = (props) =&gt; { const className = &quot;p-&quot; + props.gap.toString(); return &lt;div className={className} &#x2F;&gt;; }; ```<p>Why do this? If gap needs to be set, then break apart the Card subcomponents (Card.Title, Card.Description, Card.Footer) and let the consumer handle their odd logic that break the design system guidelines.<p>I have faced issues with Tailwind too, but I would pick this 10 out of 10 times over styled-components and such.
评论 #34337161 未加载
评论 #34336883 未加载
评论 #34336887 未加载
HuwFulcherover 2 years ago
I don&#x27;t use React or do much front-end work so I might be missing something here but what&#x27;s the problem? Tailwind is a utility-first framework. If you&#x27;re having to add so many classes inline that it makes things more difficult you can surely abstract it away within CSS files?<p>I thought the main thrust of Tailwind is that you get a sensible set of utility classes so you can mix and match them how you need? For more complicated design systems can&#x27;t you combine these utility classes into your own classes in a CSS file? You still retain the advantage of easier to read CSS and easier to read JSX.
评论 #34337831 未加载
ls15over 2 years ago
&gt; @apply is the directive that Tailwind recommend to extract repeated utility patterns. Since it&#x27;s a static definition, you would only abstract those lists into a CSS file. I don&#x27;t want to get into much details about it, but it does not solve the problems mentioned before.<p>I would like to know <i>why</i> @apply does not solve the issues in the author&#x27;s opinion. This is exactly the part where the author should have gone into details.
评论 #34337033 未加载
评论 #34337025 未加载
rmckayflemingover 2 years ago
Pretty much every thread on Tailwind will devolve into debates on CSS development&#x2F;maintenance practices. My take is that Tailwind enables a style of CSS development more akin to using a dynamically typed language. It&#x27;s really great for whipping things up and for one offs. And for so many tasks, that&#x27;s all you need!<p>But of course, there are situations where it becomes unwieldy. I&#x27;d wager that a lot of the problems people have with Tailwind are more social in nature. Which are valid problems! It just means that you need some other solution for that. Analogously, many of the benefits of static typing are social in nature; notably in enforcing interfaces between teams. I suspect people are looking for a similar thing for CSS. But that doesn&#x27;t invalidate the use cases where Tailwind is particularly handy.
EduardoBautistaover 2 years ago
&gt; Tailwind isn&#x27;t component-driven, which they claim to be<p>They don&#x27;t ever claim to be component-driven. They are utility-class library and nothing else.<p>I highly recommend using twin.macro if you are using React. It basically combines tailwind with styled components and helps immensely with readability:<p><a href="https:&#x2F;&#x2F;github.com&#x2F;ben-rogerson&#x2F;twin.macro">https:&#x2F;&#x2F;github.com&#x2F;ben-rogerson&#x2F;twin.macro</a>
danielvaughnover 2 years ago
The author makes a couple of valid points, although these aren’t reasons to not use Tailwind. Rather, they’re just the trade-offs you have to sacrifice for the benefits that Tailwind provides. Whether the trade-offs are worth it depend on your use case and your professional opinion.<p>That being said, when looking at Tailwinds problems, you have to ask yourself “compared to what?” Especially that first complaint - Tailwind is hard to change compared to…Bootstrap? Foundation? BEM? MUI? It’s vastly, vastly easier to change Tailwind code than any of those frameworks (IMO).<p>I’m a Tailwind champion not because it’s the perfect solution, but because I’ve found it to be better overall than anything that came before it.
评论 #34336962 未加载
评论 #34337088 未加载
评论 #34337204 未加载
meet_zaveriover 2 years ago
Started my web dev in bootstrap era. When I found out about tailwind and tried it in one of my side project, I never looked back.<p>In one of my prev companies, I was able convince my engineering manager to use tailwind alongside Antd and it worked flawlessly.<p>Just to make a point here, Antd is an example of design system and I used tailwind as a &quot;utility&quot; from which I can use vast amount of classes without writing seperate custom css for each of my components.
评论 #34338076 未加载
sonicgear1over 2 years ago
Please don&#x27;t follow the author&#x27;s opinion. RadixUI with its&#x27; 50kB tooltip is not something a sane person would use. This is why React websites weight multiple megabytes at times.
评论 #34337549 未加载
johnracklesover 2 years ago
This code example is explicitly not supported in tailwind:<p><pre><code> const className = &quot;p-&quot; + props.gap.toString(); </code></pre> according to <a href="https:&#x2F;&#x2F;tailwindcss.com&#x2F;docs&#x2F;content-configuration#dynamic-class-names" rel="nofollow">https:&#x2F;&#x2F;tailwindcss.com&#x2F;docs&#x2F;content-configuration#dynamic-c...</a>
esskayover 2 years ago
<i>Tailwind isn&#x27;t component-driven, which they claim to be</i><p>Stopped reading there. It&#x27;s a utility library, that much has always been blatently clear and obvious. Really poor article.
评论 #34337981 未加载
评论 #34338072 未加载
brnewdover 2 years ago
I&#x27;m still firmly in the Bootstrap camp. It&#x27;s boring, well understood by the average website visitor. Allows for rapid development and thereby time to market. I tried Tailwind once, but found the added complexity not worth the trouble. I guess it all hinges on the type of project(s) and runway.
thinkxlover 2 years ago
This is how we do it.<p>We don&#x27;t use Tailwind directly on your components (unless necessary and for adjustment only, more on this later).<p>We try to keep Tailwind as an internal implementation detail. The consumer of our components should pass options as `variant=&quot;primary&quot;` where `variant: &quot;primary&quot; | &quot;secondary&quot;;` BUT it&#x27;s okay to allow some Tailwind classes for customization on edge cases.<p>Example (by memory, syntax might be wrong):<p><pre><code> import cn from &#x27;classnames&#x27;; &#x2F;&#x2F; Definition function Button({ fill, isLoading, className }: ButtonProps) { return (&lt;button className={cn( &#x27;relative&#x27;, &#x27;inline-flex&#x27;, &#x27;rounded&#x27;, { &#x27;w-full&#x27;: fill, &#x27;opacity-50&#x27;: isLoading, }, className, )} &gt; {children} &lt;&#x2F;button&gt; ); &#x2F;&#x2F; Usage &#x2F;&#x2F; Full-width button, with some margin on the left &lt;Button fill className={&quot;ml-2&quot;} &#x2F;&gt; &#x2F;&#x2F; Regular button, with loading state &lt;Button isLoading &#x2F;&gt; </code></pre> You can even go further and use <a href="https:&#x2F;&#x2F;github.com&#x2F;crswll&#x2F;clb">https:&#x2F;&#x2F;github.com&#x2F;crswll&#x2F;clb</a> and create your own rebassjs.
redbar0nover 2 years ago
The author&#x27;s gripe with using Tailwind with components is more concretely expressed in this follow up thread: <a href="https:&#x2F;&#x2F;twitter.com&#x2F;davesnx&#x2F;status&#x2F;1329392089189265408?s=20&amp;t=yL1Q2zepqxG1ihgn_-PyDQ" rel="nofollow">https:&#x2F;&#x2F;twitter.com&#x2F;davesnx&#x2F;status&#x2F;1329392089189265408?s=20&amp;...</a><p>For reference, this is how Tailwind suggests using it with components (aka. &quot;component-driven&quot; as it says, which the author takes issue with): <a href="https:&#x2F;&#x2F;tailwindcss.com&#x2F;#component-driven" rel="nofollow">https:&#x2F;&#x2F;tailwindcss.com&#x2F;#component-driven</a><p>I think the gripes come from trying to combine the bottom-up approach of Tailwind with the top-down approach of props based styling that JS component libraries typically allows. His point being that Tailwind does not work too well with such solutions for dynamism &#x2F; contextual style overrides. You could solve it with using clsx or cva though, as seen in this video:<p>&quot;Tru Narla: Building a design system in Next.js with Tailwind&quot; <a href="https:&#x2F;&#x2F;www.youtube.com&#x2F;watch?v=T-Zv73yZ_QI">https:&#x2F;&#x2F;www.youtube.com&#x2F;watch?v=T-Zv73yZ_QI</a><p>The best way seems to be making styling a completely internal component concern, and not take in style props but simply semantic props like isActive=true and then have the component itself apply styles based on that, like NavItem.js on the Tailwind home page suggests: <a href="https:&#x2F;&#x2F;tailwindcss.com&#x2F;#component-driven" rel="nofollow">https:&#x2F;&#x2F;tailwindcss.com&#x2F;#component-driven</a><p>This practise is elaborated in this example, that has the same button styled differently by passing in different semantic props: <a href="https:&#x2F;&#x2F;youtu.be&#x2F;T-Zv73yZ_QI?t=570" rel="nofollow">https:&#x2F;&#x2F;youtu.be&#x2F;T-Zv73yZ_QI?t=570</a>
caporaltitoover 2 years ago
The guy is not happy because he still has to write CSS from time to time, yet says the classes from a CSS utility library, which prevent him from having to write too much CSS, should be thrown to garbage. Another absolute title article to make you click.
plaguepilledover 2 years ago
Gave up halfway. I try not to nitpick on grammar and spelling, but this article&#x27;s lack of editing legitimately makes the reading experience unpleasant.
jFriedensreichover 2 years ago
i am thinking about a feature that works like a reverse apply. instead of compiling the tailwind classes into the css class that uses apply, it would add the applied tailwind classes to the html class. this way all the tailwind optimizations and workflows would still work, but at least a few of the problems can be mitigated.
hakanderyalover 2 years ago
I&#x27;m going the opposite way and switching from CSS-in-JS to Tailwind.<p>While I like the css-in-js way of doing things, React seems to be moving away from runtime css generation, and I&#x27;m not sure the ecosystem will catch up (and I&#x27;m tired of playing catch up).<p>Sticking to CSS guarantees you won&#x27;t have any compatibility problems.
评论 #34338864 未加载
chris_stover 2 years ago
Instead, consider using DaisyUI[0] as a design system, which is built above TailwindCSS. As a bonus, it&#x27;s just styles, so it works with any JavaScript system (or none).<p>0: <a href="https:&#x2F;&#x2F;daisyui.com&#x2F;" rel="nofollow">https:&#x2F;&#x2F;daisyui.com&#x2F;</a>
xkcd1963over 2 years ago
Yes, this is the typical reinvention of the wheel, where junior devs (all for the right purposes) want to learn by implementing their own version. But mixed with the hipster culture of everything new is automatically better and you get discussions like that.
newbieuserover 2 years ago
tailwind is a library I don&#x27;t like in many ways, but the criticisms in this post are pretty ridiculous. tailwind is not a library offered with the motto of component driven as the author mentioned. and instead of bloated packages like radix ui I think it&#x27;s a more sensible solution. at least it gives a chance to follow a more optimal path. I think it is impossible to find an optimal way with the libraries it recommends. you should use everything just as the library intended.
评论 #34337597 未加载
neximo64over 2 years ago
These sound like gripes with React more than tailwind.
评论 #34352170 未加载
stevevover 2 years ago
Sounds more like it’s a react problem. I use vue.js and I don’t have these issues.
efieldsover 2 years ago
or do. It&#x27;s fine, really. None of us are your mom.
moneywoesover 2 years ago
How about MUI
评论 #34339507 未加载
simonhampover 2 years ago
I have to chuckle a little at these posts that seem to be &#x27;upset&#x27; that Tailwind (or some new framework du jour) is not the silver bullet that the hype train has had them believe<p>I love Tailwind and use it daily, have done for almost 6 years now and I haven&#x27;t experienced any issue I couldn&#x27;t solve<p>It certainly has never got me thinking to just throw it away or denigrate it publicly. And my solutions have worked well in a team setting - not adding any burden to other devs<p>This feels more like it&#x27;s at the intersection of React-specific problems and lack of experience with Tailwind and&#x2F;or CSS in general<p>I can see some of these problems being frustrating, but because the author seems to just be sounding off without much effort to express attempted solutions, I&#x27;m flagging because I feel like this is just anti-Tailwind inflammatory BS<p>Edit: Title also needs to indicate this is from 2021
评论 #34337055 未加载
评论 #34337092 未加载