Tailwind: style your site without writing any CSS
jvns.ca
jvns.ca
Tailwind, along the same lines, proposes a contrarian idea and it will only make sense once you start working with it. Here's what I have seen happen frequently: As the CSS grows, so does the bloat and repetitiveness of the same basic style. Let's say you want to position elements in the center of a component? "display: flex, align-items: center" easy. But what do you do when you encounter that same requirement again? Creating a utility class and replacing existing once will be a pain, so you add the same styles again. And that's how folks you end up with a megabyte of CSS doing a job that could be done in <100Kb.
This pattern is more pervasive than you think. The fundamental problem is that we are not thinking about styling in terms of composability of basic styles.
The benefits of utility classes outweigh the cons. You can iterate faster, you don't have to fight the framework, you don't have rethink abstractions at every point ("this style belongs to a component or a utility class") and as CSS becomes more expressive you'll need fewer classes anyways. I hope Tailwind takes off because styling definitely needs to be less painful than it's today.
What size site do you work on? How often do you have to completely change an interface, or move a component from one place to another without it breaking at all, and how well does that work for you with Tailwind? How do you plan to scale this codebase consistently across organizations, teams, potentially platforms?
Tailwind and the frameworks like it are absolutely terrible at scale. I've spent years of my life trying to remove functional css from sites trying to scale while it holds them back.
When I started here, I sort of “inherited” a large stylesheet written in the classic BEM/Tachyon style of CSS. I can see why the author chose this method, because at the time the website was small and functional classes seem like a really good thing, as they help you get up and running quickly.
Over the years, however, the site got more popular, and now the demands of the interface are increasing. At one point, it was perfectly OK to do, say, “container mt-5 mb-5 p-20 text-green” etc. This flexibility allowed the site to grow, and while the CSS did bloat, the impact was seen as negligible for years.
Now the site sees 50-80k+ DAU, and seeing as the business is very established, it makes sense that we would want to add bells and whistles to the UI that wasn’t on the roadmap those years ago, like theming, widgets, or simply making a previously non-responsive page responsive.
In Tachyons, and in Tailwind, the abundance of utility classes means that even the best, most organized authors will create inconsistencies. The original container styles from earlier might look something like “container mt-5 mb-5 p-20” in one place and “container mb-30 mt-30” or “container bg-dark pt-5” in others.
It may seem trivial to just add and remove classes at will, but it isn’t. Removing a margin-bottom from one element inevitably affects the position of another on the same page, and trying to reconcile these inconsistencies _usually_ means an override, because figuring out how to rearrange functional classes without breaking anything else is a time suck.
Removing this style of CSS from the project has been tedious, but necessary. Now that we build with small, immutable, scoped components, its trivial to drop in a new component (or remove it) from anywhere without affecting anything else. And you avoid the unexpected inconsistencies created using utility classes by, well, avoiding them. As someone that used to love BEM, tachyons, Atomic CSS, etc., the lack of scope, unpredictability and huuuuge bloat created by overrides steers me away from it even for the tiniest of projects.
Any suggestions for further reading on "small, immutable, scoped components" ? I'm half sure I know what you mean and entirely sure I don't understand it well enough to explain it to somebody else.
(thanks for your already expansive reply)
I like to say, that with components, you encounter “a new level of bugs.”
With Functional CSS, you deal mostly with incidental bugs. “This container has margin 10 and this one has 15!” or “This text-red is overriding all my text!” Individually, these are annoying, but together they can compound into unfuckable problems. Right now I’m working on rebuilding a header that was styled with this approach, and ultimatley wound up unable to remove certain classes without breaking other elements. Something as simple as moving the text from one side of the screen to the other involves building an understanding of how they work individually, which is very challenging in a site as large as ours.
Enter my new header, a component. Its got a parent of .HeaderComponent and everything is scoped inside of it. If I delete, say, a .Link here, it doesnt affect links elsewhere on the site. And since I include re-usable mixins for base styles, like text, its easy to (say) @include BodyFont; or HeaderFont; without affecting the page or the site as a whole.
What I mean when I say “a new level of bugs” is that how and why you build things becomes more important. If I build a header component, but a large change happens elsewhere on the site, its unlikely I will change my original component. I’ll make something new and call that, instead.
In this process you can wind up with poorly built components, things that wind up not being used as much as you thought, etc. But the beauty of it is that getting rid of them is SIMPLE. I made a lot of mistakes when I started building doggos.com with components, but I’m really excited about how easy they were to remove. If you just make something new when you need something new, you wont have a bunch of legacy code following you around everywhere.
That probably isn’t a greaaat explanation, but I’m very happy to expand further or give you some links. In particular, Airbnb.design has some great lessons on why they ultimately went this direction, and they do a much better job of explaining it than I!
Much appreciated!
I've only used Tailwind briefly for some side project, but I thought the docs made it clear that whenever you have a situation where you feel you're repeating styles you should extract them into a new CSS class. There's a whole section dedicated to that in the docs:
https://tailwindcss.com/docs/extracting-components
How would this have been prevented if those same developers weren't using Tailwind and instead simply created .container1, .container2, and .container3?
> Now that we build with small, immutable, scoped components
What do you mean by the word component? Are you talking about a React or <insert framework here> component? I don't really see how it's related. It seems like your team quickly iterated and didn't think forward about creating a common look for "containers" until a good amount of development was done. The common look could have been accomplished by extracting the common styles like the above link suggests or creating a common "Container" UI component with isolated styles. The mistake was not thinking ahead and seems unrelated to Tailwind IMHO.
> Tailwind and the frameworks like it are absolutely terrible at scale.
My experience has been the opposite. BEM is terrible at scale. You write the CSS, but then never dare change it, because you have no idea of the consequences of those changes. Developers end up duplicating BEM components for their use case, because it's safe. Which just leads to more CSS code. It's also worth noting that we're seeing more and more large companies move to utility based CSS, including GitHub and Heroku.
We accomplish this in our web app (over 500 kloc) by simply giving each component’s top-level element a unique, formulaic, memorable CSS class (which is very easy to do with SASS/SCSS). And each component gets its own CSS (or .scss) file, HTML file, JS file(s), and I18n directory. The app loads each component’s CSS when that component is loaded at run time (which could be during startup or later). I just don’t see how one could get more straightforward than this for a large app.
We do have some classes that are included in the base-level stylesheets and shared among components, but we only use those when it would result in less code than not, or when necessary for themeing.
It may take a lot of effort to build this kind of architecture, but once you’re there it’s a breeze to create, compose, and maintain UI components.
Plus, component isolation has really slow polyfills. None of the Google stuff as of late runs on anything other than Chrome for like a year after launch because it's too slow and broken -- everything is being rewritten in Polymer, which relies on browser support for component isolation.
As for eschewing the style cascade, yes, that is happening when we isolate each component's CSS. However, wouldn't using Web Components proper have the same problem? And yes--it would be a very large task to add a dark mode, as you say. Each component would have to be visited. However, when we drop IE11 support, CSS custom properties will make this potentially much easier.
We don't copy-and-paste CSS often (remember we're re-using components and composing them everywhere). If there's enough commonality for CSS copy/paste to be tempting, it's probably time to either revisit how components are being composed (do we need to create a new component, or maybe have these 2 similar components inherit from a base JS class?), or add those styles to a top-level stylesheet and use shared CSS classes.
In general, with component CSS, you will tend to avoid the cascade, except within your component. This is actually where utility classes have some value - if they're scoped very tightly to the parent, and their effects are well-understood - then your single purpose class can add an easy way to do simple updates.
That being said, for my part, and on my own website (doggos.com) we do not use any form of utility classes whatsoever. The entire website depends upon isolation, and through this isolation, I have a degree of control that I've not found in applications that have opted for other methods.
In short, it's worked very well for us.
As for your dark mode example... you should take a look at how Apple made dark mode a reality with their new Mojave update. I think you will be surprised at the level of isolation their interface demands and, although we're no longer talking about the web here, just how easy it was for them to implement...relatively speaking.
In short, I can make a site go dark with components, no problem.
I think Tailwind is quite an interesting approach, but to play Devil's advocate: how much bigger was your HTML? With all these class names, you're basically moving some of the entropy over from the .css to the .html, right?
- If you don't like CSS, this will not help you write less CSS, it will only make you write it inline and using a weird syntax.
- If you want to do the sensible thing and compose your styles into components then you'll still have to write CSS with the weird syntax and add a PostCSS to your dev pipeline. Not to mention that you'll still have to have some kind of system for your class naming.
- The order of the clases does not matter, the specificity is decided by the order in which they appear in the source. I can see all kind of untraceable bugs coming from that.
I've used BEM and SMACSS and similar before and I think they are useful as a naming convention for teams but I don't think of them as great tools to writing better CSS. In my humble opinion CSS-in-JS solutions are closer to a great abstraction. I quite like both StyledJSX (for react) and .vue files in which you can write plain css and forget about the global aspects of CSS and the cascade for the most part.
But I can see why some people will dislike that as fiercely as they dislike tailwind.
I think Styled System is a better abstraction than tailwind: https://github.com/jxnblk/styled-system it's a React library but I can see it's principles could be extracted successfully to plain CSS.
Css in js is very efficient if you don’t need any css inheritance. Tailwind is just inefficient for the browser to do all those lookups to resolve the final style bag.
I’m not sure why I would ever use tailwind. It’s yet another archaic syntax I have to keep in my head.
I suspect people who immediately dislike this maybe are not using some type of component-based UI. CSS classes are all about code-reuse. If you have the concept of say a "button" in your UI, and you are copying your button markup every where you use that "button" then it certainly makes sense to have a class for your button markup that encapsulates the styles for that button in a style sheet somewhere.
If using a button component however, you've already created a place for the concept of your button to exist. At that point if you go on making a class in some style sheet that also represents the concept of your button, now your button concept exists in multiple places, linked together by one or several class names. That seems a lot messier to me than using utility first styles, but I don't think it really makes a huge difference one way or another.
.i-dont__find-bem--very-readable.
If you're into knowing where your class came from, it seems tailwind would be even better for you because now you have access directly to your styles right there in your markup. Skip the class step altogether!
I treat my name spacing the way I do in most source code. All the code for a unit is in the same file or in files called out from that file.
If you’re not nesting in Sass you’re missing out on some of the better parts.
https://medium.com/@davnicwil/how-i-learned-to-stop-worrying...
Tldr: for me, classes make more sense for reuse in simpler content-heavy scenarios. For anything remotely complex or webapp-like, I think they are the wrong abstraction.
Whether Tailwind is functionally and pragmatically better than inline styles isn't even important. It looks like inline styles, so the first reaction of almost any experienced designer/developer that looks at it is to make that association and squirm in discomfort at its mere appearance.
The author of Tailwind suggested I read his best effort at explaining why this makes sense.: https://adamwathan.me/css-utility-classes-and-separation-of-...
Towards the end of the article it started clicking for me.
“With inline styles, there are no constraints on what values you choose... Utilities force you to choose...
You can't just pick any value want; you have to choose from a curated list. Instead of 380 text colors, you end up with 10 or 12.”
these inconsistencies compound, especially across teams.
It's a good realisation that there is no real separation of semantics and styling between HTML and CSS. XSL would have been one solution, but it was just too XML-ly. Personally I found it a joy; I could design my pages with pure semantics alongside a turing-complete stylesheet.
However now we have web components - your HTML and CSS are tightly coupled, but scoped. And the semantic / styling separation is provided by the shadow DOM. So no need to create inner platforms like Tailwind.
When I write CSS, I use a lot of shortcuts. I simply write "mt5" and then press tab, it then auto completes to "margin-top: 5px;". If I write "tdu"+tab and then it goes "text-decoration: underline;". The IDE also shows me in a drop down all the options that can be used after writing "text-decoration".
Changing standards because you do not want to learn or remember something is the perfect example of programmer "laziness". Why remember this super common language when instead I can develop and remember a new obscure abstraction instead?
Even the framework that they are using proposes better alternatives.
“Tailwind encourages a "utility-first" workflow, where new designs are initially implemented using only utility classes to avoid premature abstraction.
While we strongly believe you can get a lot further with just utilities than you might initially expect, we don't believe that a dogmatic utility-only approach is the best way to write CSS.”
Read this page: https://tailwindcss.com/docs/extracting-components/
A class based rapid prototyping framework is a powerful tool, don't get me wrong. However, like all tools you should only use them when they truly are needed.
How so? If what I need is (as the author describes) to occasionally make a quick relatively-usable site, and I want to do some styling on it, and then forget about frontend UX until I need to do another small site 4 months from now, how will this pattern bite me?
So you write your button one time in a reusable button component, then reference the component and avoid writing the same 20 styles again. I think this has benefits as it keeps all the information for a single component in the same location, making it easy to understand and edit the component from a single location.
For people in that niche, frequent tweaks/changes to the styling seem unlikely: I'm going to make the site once and unless it breaks I'm unlikely to come back to the code for it.
The parent comment I replied to makes the direct claim that this class-based pattern will bite me, and I'm curious if somebody can help me figure out how that would happen.
I understand that maybe adding a bunch of classes for every element will increase the overall size of the page but if it's served with gzip compression doesn't it actually (maybe only technically) work better to have repetitive classes everywhere instead of unique class names?
Look at the button from his article:
<a class="text-xl rounded bg-orange pt-1 pb-1 pr-4 pl-4 text-white hover:text-white no-underline leading-loose" href="#">Buy for $10</a>
That's way too granular.
On this page it documents how you can create component classes https://tailwindcss.com/docs/extracting-components/
<button class="btn-blue">
Button
</button>
Then in your style .btn-blue {
@apply bg-blue text-white font-bold py-2 px-4 rounded;
}
.btn-blue:hover {
@apply bg-blue-dark;
}On a small one page website, do use them. However in something more complex like an e-commerce website theme or a complex web app, you will regret it quickly.
<a class="text-xl rounded bg-orange pt-1 pb-1 pr-4 pl-4 text-white hover:text-white no-underline leading-loose" href="#">
is no better than
<a style="font-size:16px; border-radius:5px; background:orange; color: white; text-decoration: none;" href="#">
It is simply a fancy way to use inline styles.
One of the selling points of CSS is the ability to scale and refactor very quickly and easily. Class based frameworks remove all those benefits. Extracting components and building sementically is the solution. As I said in my previous comment, that framework they are using supports it. They say it themselves:
“*While we strongly believe you can get a lot further with just utilities than you might initially expect, we don't believe that a dogmatic utility-only approach is the best way to write CSS.*”
I have worked on many contracts where the client came to us because their current web agency wanted to charge crazy prices to refresh their website's design (e-commerce websites change at least one a year). Almost every time, those projects are a pain for both the team and the client because the previous developer decided to be lazy and use classes or inline styles everywhere. .btn-blue {
background:blue; color:white; font-weight:bold; padding:
4px 2px; border-radius:50%
}It may be hard to see now how it will bite you now, but I promise you, it will. It would take hours to explain why, but I am speaking from years of experience here.
There is a reason large organizations have abandoned this approach, and it isn’t just personal preference.
This talk gives a pretty good explanation, Airbnb.design, Netflix, Facebook, and Instagram have many others
If an abstraction makes it easier to do what you want to do, it's a useful abstraction.
The point of a broad set of utility classes is to have predefined and discrete classes that map to conventions your application uses. Here's a few examples from an app I use:
.u-colorPrimary { font-color: var(--utils-css-c-primary) !important;; }
.u-textSmall { font-size: 0.75rem; }
Each of these are a "standard" that we use throughout the app. There are NO one-offs. These can then be composed into "component" classes (e.g. .Button, or .TextInput).
The benefit is mostly threefold:
* Maintainability is great. No hunting throughout the templates when you want to change the primary colour. Just update the .u-colorPrimary class, or its underlying variable. * Our developers can look at a design and mostly do it themselves. No need for a CSS pro to come in. * We can package these into a node module and share them across our apps.
You're right: this is laziness. I don't like to repeat myself, and I like consistency.
I prefer to use SASS variables along with a strict build system that refused to build if the developer isn't using variables that are injected via a config YAML file. In the end, we are both working in a similar way.
That being said, ".u-colorPrimary" is great. You can easily refactor it and it should scale well. However, ".bg-orange" and ".text-white" aren't great.
This button from the article is really bad:
<a class="text-xl rounded bg-orange pt-1 pb-1 pr-4 pl-4 text-white hover:text-white no-underline leading-loose" href="#">
They should at the very least made a component with the styles and then apply via ".button" class. .resources {
@include .centered
@include .wide-margins
@include .light-bg
}
It seems like every one of these styling tools is just polishing a turd that is a turd for no reason. I can't imagine why the above would be difficult, it wouldn't have to change anything about the actual application of CSS rules, it could literally just be a simple preprocessor.Sure give me a library of common ways of doing something. That's great. But the lack of basic code reuse for CSS is staggering. Even if you're doing reuse with SASS you're stuck with the fact that you end up generating a CSS File that's 4-5 times larger than it needs to be.
.resources {
@apply centered wide-margins light-bg;
}
And that's exactly what Tailwind is about, btw!Sadly, as you point, it's not vanilla. It works, though.
:root {
--toolbar-theme: {
background-color: rebeccapurple;
color: white;
border: 1px solid green;
};
}
.Toolbar {
@apply --toolbar-theme;
}
Rather than arbitrary CSS classes?Tailwind comes with its own @apply: https://tailwindcss.com/docs/functions-and-directives/#apply
Of course you can say now I mixed style with HTML but if you never intend to change style separately from HTML then why introduce the mental overhead of indirection?
And for example in React to build a component with conditional styling I use classNames and use props that correspond to classes.
That's not really the case since SCSS became a thing. If SCSS doesn't help you, Tailwind won't, you can ignore their classes just as you could ignore preset constants.
Honestly, to me it seems like people are just starting "fresh" with a benefit of some experience, and ascribing the benefits of experience to the tool.
I can't believe that mnemonic based languages are easier and more readable than something closer to a natural language. And with the assumption that code is written for humans first, computers second, what is the point of inventing a language that's less readable than the one it's trying to replace? CSS compresses particularly well, as every Atomic CSS based framework tends to point out on it's landing page!
<img class="block h-16 sm:h-24 rounded-full mx-auto mb-4 sm:mb-0 sm:mr-4 sm:ml-0"
<img class="block height-16 small:height-24 rounded-full margin-horizontal-auto margin-bottom-4 small:margin-bottom-0 small:margin-right-4 small:margin-left-0"
After spending more than, say, two hours with Tailwind you'll probably read the first line much faster than second one (since there's less to read and you don't need to scroll). Humans are very good at pattern recognition, and you'll quickly read "mb" as a symbol in itself and not as "m[argin] b[ottom]".> I can't believe that mnemonic based languages are easier and more readable than something closer to a natural language.
Well, it's worked out pretty well in mathematics. This is not about file size at all. It's about defining an "alphabet" of common concepts.
<img class="
block
height-16
small:height-24
rounded-full
margin-horizontal-auto
margin-bottom-4
small:margin-bottom-0
small:margin-right-4
small:margin-left-0
">
This also has the benefit too, that if you use version control line-based diffs to see what's changed, it will highlight the specific css class name that changed. Handy if you need to ensure that whenever you change the bottom margin, you can see at a glance whether the small prefixed one has been updated too.On the other hand if you regularly need that many classes to style an element, perhaps it's a good place to refactor commonly occurring class names into a set, and label that set with a meaningful identifier.
As for mathematical notation, it's about as understandable to me as my understanding of Hanzi.
I recommend this post by Adam to anyone who is interested in learning more about utility first CSS.
https://adamwathan.me/css-utility-classes-and-separation-of-...
And due to the lack of tooling, it's hard to refactor CSS (removing duplicate code, etc.) so I'm not sure how scalable it is to adhere to what the OP says for a long time.
Last time I migrated a project from Tachyons to Tailwind, it was quick and painless.
I searched around and Bulma seemed ... "not insane" which was good enough for me. And it is good, and good enough. But I can easily see how you could start fighting against Bulma if you wanted to do much customizing.
If I ever get caught between a rock and a hard place and need to do stuff not easily wrought in Bulma, I will check back on Tailwind.
Functional CSS makes for an unscaleable, inconsistent, unmaintainable dumpster fire of styles that is objectively worse than just writing regular CSS.
<sarcasm> But it's convenient, right? So who cares! AirBnB, Facebook, Walmart, Github, and Twitter are all probably wrong anyway. </sarcasm>
I interviewed Diana Mounter who leads their design systems team about this a while back: http://www.fullstackradio.com/75
Check your facts ;)
Airbnb (332kb, 54 text colors, 72 background colors, 48 font sizes): https://cssstats.com/stats?url=http%3A%2F%2Fairbnb.com&ua=Br...
Walmart (178kb, 32 text colors, 22 background colors, 64 font sizes): https://cssstats.com/stats?url=http%3A%2F%2Fwalmart.com&ua=B...
Twitter (630kb, 36 text colors, 50 background colors, 46 font sizes): https://cssstats.com/stats?url=http%3A%2F%2Ftwitter.com&name...
GitHub (658kb, 157 text colors, 141 background colors, 55 font sizes): https://cssstats.com/stats?url=http%3A%2F%2Fgithub.com&name=...
These are not stylesheets I want to emulate. As I mentioned in my other reply, GitHub is actively moving towards a more utility-based approach to solve this problem.
Compare this to a fairly large app where the CSS and markup were completely rewritten using Tailwind by a friend of mine recently:
https://cssstats.com/stats?link=https%3A%2F%2Fapp.churchsoci...
41kb (8.1kb gzipped), 15 text colors, 44 background colors, 22 font sizes. Pretty good, no?
This is all the CSS needed to render almost the entire app from mobile to desktop widths, in both light and night themes. The "utility CSS" is generated by a framework and not something engineers have to be concerned with when writing components.
"What about semantic classnames? Separation of concerns? It looks ugly, is going to be hell to maintain, won't scale.. may as well use inline styles!"
I did a conference talk about my own experience moving from BEM to utility-first CSS, you might find it interesting
I see this as an anti-pattern, because to me it looks like inline styles with extra steps. The only thing it avoids is accidental strong specificity.
The reason we have CSS is that it's really easy to make HTML unreadable - after all it's essentially a 1D medium(lines of text) trying to describe a 2D space.
Also this is switching things around. Now your html depends on your css classes and not your css depending on your html. No more broken css when a dev modified the html structure and didn’t realize that one of the hundreds of lines of css now doesn’t get applied right.
You can achieve the same, but with much less clutter using BEM. Or even better: BEM + SASS.
The difference is that inline styles can't use several important CSS features, like media queries or pseudo-classes like `:hover`, `:focus`, etc.
You have to first be convinced that inline styles are not inherently an anti-pattern to understand a framework like Tailwind. After that, the benefit of Tailwind is that it's like inline styles, except with the ability to style elements in different states and at different screen sizes.
I wrote a post a while back that is my best effort at arguing for the validity of presentational class names if you're interested: https://adamwathan.me/css-utility-classes-and-separation-of-...
Say you have an entire application with a dozen primary pages, plus several dozen modal windows and other sub-pages. If you want to make a global change, like, "Change all the OK buttons in my entire application to have rounded corners and a gray to red gradient" then you have to go back and make a change to every button you have in the application. The whole idea with changing the CSS was that I defined a semantic CSS (e.g. "OKButton") which I used in all the places that had a common meaning, and then I could change the look of the entire application in one place.
"Limits & standards. With normal CSS, I can make any element any width I want. For me, this is not a good thing! With tailwind, there are only 30ish options for width"
It’s the difference between working with Lego and working with ordinary hunks of smooth plastic.
E.g., With Ruby and Python and Java you lose a lot of the flexibility that pure C gives you. You can't directly manage memory directly any more, for example. Is that a bad thing? Not for most people.
Note also that one of the major goals of an operating system is to limit flexibility. The first thing an OS does on starting is to lock a bunch of functionality away from any other code. Similarly, virtualization and containerization are mainly about removing capability.
Imagine that your designer puts together a design system built on a soft grid. The rules in the design system are what ensure consistency across the site.
If you have a team of developers, sooner or later you'll manage a junior dev who interprets the design as a pixel perfect layout, and starts defining widths on elements per their own personal interpretation. Maybe they eyeball it, maybe they measure it, maybe they measure it but don't include the border.
You can catch such things through training and code review, but it puts the burden of managing design consistency on a senior engineer. Starting out with a constrained system is one easy way to ensure consistency of design across large projects.
I fear that many will not prefer attribute bloat in their markup.
And many are moving to React, does this sort of toolset matter anymore? Not being negative, genuinely serious. Does this tool make sense for apps going forward? To me it seems Tailwind is for little html things.
I plan to use tailwind in all future green field projects!
Enforces style, kills duplication, speeds up development. Ahh the benefits are huge!
Personally, I have been using Tachyons with React for the past couple months, and it's been a blast. Compared to writing html templates with Emmet and css with Sass, I feel as if I am more productive and like I can reuse more components.
It's worth a try if it interests you!
I wrote a tiny (1kb) library to make this easier. For anyone working with React and functional CSS, I hope it's helpful:
https://wizardzines.com/zines/tcpdump/
Reminds me of many computer publications in the early days
> By comparison Tailwind seems really heavy (over 1.5x larger than Bootstrap!), but it turns out that this comparison isn't totally fair.
'Curating' what developers are allowed to do has been the focus of the last few jobs I've declined. "The guys at the other office are too dumb to learn (React|Angular|CSS|tech X). Obviously, we need a team to invent something that uses (React|Angular|CSS|tech X) behind the scenes but has a totally different API and no easily searchable documentation or support outside of our company."
Tailwind looks like one of those escaping into the world, when telling your devs to pay attention to a style guide would have been the easier solution.
Technology does not have a glorious track record in solving cultural issues.
- The 'scale' at which they think a framework like this doesn't work (number of users, devs etc).
- The scale of the projects they work on.
Who even says a framework needs to be adopted by tech giants or work at 'scale' to have any credibility?
A utility-based approach has been adopted at the last 2 companies I've worked for and it's been very effective, often when working with very complex designs on medium-sized sites (that serve less than 100k users/month).
Some of my previous colleagues and I work on https://github.com/friendsthatcode/flavourcss, which was inspired but some of the ideas behind Tailwind and our own work.
With elements with a large number of style rules, you add a lot of very long lines to your html.
This would be a nightmare to work on/maintain.
In the HTML, sure. But so what? It gets compressed in transport so there won't be significant overhead there (similar to how remote desktop protocols that send images with compression turn out to be just as efficient as those that tried to send intelligent drawing commands), and the browser has to compute the final style for each element anyway so there's no overhead in-memory either.
> This would be a nightmare to work on/maintain.
HTML is an output format, you don't edit/maintain HTML any more than you edit/maintain binary machine code. And keeping the styles inline allows better encapsulation: the styling for each component lives in that component, you don't have the spooky action at a distance of child selectors.
1. People arguing against this are arguing against utility classes and not arguing against tailwind.
2. Tailwind is different - it’s a toolset allowing you to build your own framework - you can use the tailwind config to define your variables and use BEM or what ever you want.
3. Tailwind is utility “first” - so it provides all the utilities you need, YOU decide how to use them, put them all in your HTML if you like, or make components out of them, include them into an existing project, etc.
So everybody here who is being negative towards tailwind regarding utilities is wrong - because they haven’t understood tailwind. - your arguments may be valid for utility classes, but this topic is about tailwind, so your spreading misinformation.
Say you want a div to be a specific width: 135px, how do you make it without writing any CSS? Or you want a specific shade of a colour? Or you want to style things that are not in your html (third party widgets).
So you actually don't have to think about specific widths while you're building, you reference a width that is already set up in your stylesheet!
I find that it improves the design to dev workflow. You experiment with design in a design tool like Sketch, and then translate your final idea or rules into a stylesheet, which is the basis for your live prototyping in editor & browser (wrapping HTML elements and referencing styles in your stylesheet).
but if you want something not provided explicitly by Tailwind, you have to write it yourself.
Even though they are compact you probably end up having lots of unused CSS code in your website.
So if I were to every try to design a page, I want all the relevant design items there when I am figuring it out, and then when I am done, I don't want to see them again.
So if you spend a lot of time designing the html/css then this approach makes sense. I don't want to jump into the css file and then back in the html file.
However, if I want a particular look and feel for a site, and then knock out the css, then I want the css in a different file and then I want to focus on the layout and the logic.
So my guess is that the original author builds lots of new sites and moves on. My guess is that the original author does not build one large site for a large company that has a consistent look and feel for years (till the rebrand).
If I wanted to do that I would have used the ‘style’ tag.
Is this ignorance common among those for whom functional CSS makes sense, or are there any CSS experts who like it? I'm bewildered by the popularity, as I am by several other fashions.
Sometimes I wonder if these choices come from blog-driven development. I used to feel a bit insecure that I didn't go to school for computer science. I tried to make up for that by reading books, many books, cover to cover. Reading a great book cover to cover gives you a coherent understanding of the beginning, middle, and end of a language or tool. Also I read references: the list of core PHP functions, the jQuery API, and the list of CSS attributes. I didn't memorize them. I just tried to understand the gist of each, filed in the back of my mind, enough to prod me to find it in the reference when I needed it. But if you are learning by blog and Stack Overflow, do you ever come to an overall, comfortable understanding of something?
I grant you that it will take some time, but so does learning these frameworks. The frameworks seem to fix one problem while planting three more. And Julia Evans is a technically minded person. She has written about Git and the Linux command line. Which is more complicated, Linux or CSS? I had always thought that HTML and CSS were meant to be softballs, for people who are geeky but maybe not full-fledged programmers. HTML and CSS were the first languages I learned, but my coworker stressed to me that they weren't full-on programming languages.
> It’s 2018! All websites need to be responsive!
I wonder if responsiveness is another cause for this trend. I agree that making pages that shrink and fold for various screens might put some novices over the edge. But looking the simplicity of Julia's website, maybe all she needs is a viewport meta tag.
Another advantage I've had is my lifelong interest in graphic design. Before I knew CSS I knew about color, fonts, white space, etc. So I'm sure that made learning CSS easier for me. But for those who aren't into that, why aren't templates and stylesheets from other people enough? They've already chosen fonts and colors and margins and stuff that looks good together. They give classes for various kinds of pages and sections. Maybe you're somewhere in the middle, where you're not adept enough to write your whole CSS from scratch, but you want more customization than just using a general stylesheet. But why can't you tweak it? If you're smart enough to use Tailwind, aren't you smart enough to fiddle with some attributes in a stylesheet, make the corner rounder, make a font bigger, etc.?
I truly am interested in understanding, if possible. CSS has a few things that are mildly annoying, but just mildly. Nothing would ever make me want to do something like this. Truly I am bewildered!
One more thing: my attention is spread across many complex applications, thousands of lines of code, and I am in charge of the full stack (JavaScript, HTML, CSS, PHP, Apache, SQL). So it's not like I get to spend all my time focused on the front end. Yet my users have told me that my pages look nice. I'm spread thin, but I've never wanted to use anything but stylesheets, no BEM, no SASS, just good, old-fashioned selectors.
.w100 { width: 100%; }
.nopad { padding: 0; }
etc. to modify the "semantic" classes where needed, in essence creating a mini-framework for every new project.