DEV Community

Cover image for Moving From Tailwind To Vanilla-er CSS

Moving From Tailwind To Vanilla-er CSS

Mike Rogers ✈️ on May 12, 2021

I've been playing around with Tailwind CSS a lot since it's release, and so far it's been really impressive to see its growth over the last few yea...
Collapse
 
terabytetiger profile image
Tyler V. (he/him)

Having to setup base styling for semantic HTML feels tedious

This is absolutely the most jarring part of Tailwind, and unfortunate that it's inherently the first thing you experience when starting with Tailwind.

I'm honestly surprised that there isn't a collection of standard styles (at least I haven't heard of any yet) that has a few baseline starters to "fix" preflight and offer a quick starting point to get some standard styling back.

Collapse
 
mikerogers0 profile image
Mike Rogers ✈️

So much yes @terabytetiger !

When I first installed Bootstrap the first experience was "Everything looks pretty decent", but Tailwind often feels like a I'm starting from a blank slate. I think I'm in the same boat as you where I kind of expect semantic HTML to render nicely.

Collapse
 
owenmelbz profile image
Owen Melbourne

Tailwind isn't designed to give you a "generic" base style - it wants you to create your own visuals exactly as you need them - For us this is perfect because every design we produce is unique, if we had to remove all this extra fluff added for us it would be even more of a pain.

If you need a base style - then you create your own that you can pull into future projects, or find a UI Library that does it - there's plenty that people have already created :)

Collapse
 
terabytetiger profile image
Tyler V. (he/him)

In researching something else, I have now stumbled upon tailwindcss-typography.netlify.app/ which (kind of) resolves most of my complaints here.

I wish the .prose didn't have to be added everywhere to apply it, but I guess it's better than nothing 🤷‍♂️

Collapse
 
extrabright profile image
Alexis

I agree. Utilities are great, and Tailwind took it to the next level. However, something doesn't let me go all in for that. I still prefer Bootstrap. They have introduced utility classes way back, but maybe because of a lack of proper documentation and example, people didn't know exactly what to do with them.

Because of this, I've created a project in which I included a bunch of utilities using the Bootstrap 5 API. Now you have the best from the two worlds: basic components and utility classes for faster customization. Here's a link to the docs: webpixels.io/docs/css/1.0/installa...

Collapse
 
chasm profile image
Charles F. Munat

Tailwind, like Bootstrap and all the rest, is for developers who can't be arsed to learn proper CSS. It's a crutch. And when you can't walk, a crutch is great. But eventually you begin to see the downsides of walking with a crutch. You want more.

In a long career as a developer, I have used all kinds of frameworks and libraries. I've mostly given up on frameworks. They make it easy to get started, but eventually they get in your way and make things much harder.

Libraries are a bit better, but depending on other devs to maintain their code, keep it secure and tested, keep it up to date, etc. is a fool's errand. So I have concluded that the fewer dependencies, the better. Add one only when you need most or all of its functionality and writing it from scratch would be onerous.

There is nothing that any of these UI libraries gives me that I can't add myself quickly and easily -- and I've used them all going back to the first versions of scriptaculous. With CSS variables and CSS modules, there's really no reason to use anything else -- unless you simply can't be bothered to learn CSS.

As for the cognitive load of context switching between JS/TS, HTML, and CSS... please. Writing HTML as JSX or CSS as CSS-in-JS is the same cognitive load as putting it in a separate file. Using separate files keeps each clean and focused. It's not about separation of concerns but about separation of duties.

Svelte does a nice job of separating the duties, but then forces them into a single file. That's too bad.

When I code, I keep my component in one pane and my CSS (module) in the pane next to it. If I've drawn my boundaries correctly, all the code in each pane fits on one screen (admittedly, I have big screens). It's all right in front of me. And if I keep to the single responsibility principle, those screens stay short and focused.

That is how you reduce cognitive load -- not by memorizing yet another DSL so you can add ten classes to a component. And Tailwind promotes breakpoints (sm, lg, etc.), which is clearly not the right way to do things. Interfaces should adapt smoothly to changes in the size and aspect ratio of the portal and the zoom.

I know Tailwind is the new hotness right now. I've been forced to use it more than once already. But in a couple of years it will seem obsolete and foolish. Why wait?

Collapse
 
kirkcodes profile image
Kirk Shillingford

Bookmarking this for viewing later. If I ever get this advanced at writing css this seems like a great guide. Excellent post!

Collapse
 
mikerogers0 profile image
Mike Rogers ✈️

Thank you @kirkcodes !

Collapse
 
andreasoverland profile image
Andreas Øverland

It looks like we have a shift towards using more "vanilla" code. Both in CSS, JS and HTML in general. I really like that trend. Vanilla is a loaded word though. I think it has become a hallmark of something "not great". But I think many of us has experienced the actual "not great" feeling of going in to maintain a webapp written perhaps 2 years ago by using all the libraries&frameworks that were cool back then: If you chose to upgrade the libbraries&frameworks, you are in for one helluva ride. On the other hand, if those webapps were written using mostly vanilla tech, you may end up not having to do a single upgrade. Go Vanilla!

Collapse
 
thebouv profile image
Anthony Bouvier

I seriously hope we are on a trend towards more "vanilla" code with CSS, JS, and HTML. I'm appalled at the current state of front end over-engineering.

Collapse
 
mrkbr profile image
Mario Kober

Every few month I look into Tailwind but after reading and trying to style my first components, I always cannot believe how long and ugly this classes look and feel. Utilities are okay for some things. I have my own grid system so I can already put anything into the right columns as I wrote HTML but after that I switch to CSS and write the styles of the component - without almost ever having to change the HTML again, with auto reloading. This is no way worse than Tailwind. I just don't get the advantage. But of course I know - it is not your fault TW, It is mine 🙃

Collapse
 
owenmelbz profile image
Owen Melbourne

Do you think you'd be up for revising the "Preflight" and "Javascript Dependencies" points to something potentially more (excuse the term) "accurate" ?

Preflight - this is completely optional, just don't include the directive for it - in fact you can add normalize if you like? Maybe just a revision to say you can disable or replace it if you want.

Javascript dependencies - If you want to avoid adding TW to your build chain, simply use the official CLI tool which lets you build on the fly without touching the rest of your code base. From memory it's a simple as "npx @tailwindcss/cli build" (plus some extra args)

I appreciate these are things that have caught you out, but they're not faults of Tailwind, they're caused by how it's been used. If you drive a car into a river and complain it sank - it's not the cars fault :P

Collapse
 
terabytetiger profile image
Tyler V. (he/him)

Preflight - this is completely optional, just don't include the directive for it

While this is true, I don't think it's particularly relevant to the author's point - which is that when you follow the Installation page's instructions, you end up with fully reset styles and it can be jarring to new users.


Javascript dependencies - If you want to avoid adding TW to your build chain, simply use the official CLI tool which lets you build on the fly without touching the rest of your code base.

The first line of the installation page which discusses this option is:

For simple projects or just giving Tailwind a spin [...]

and under the "Using Tailwind via CDN" section there's this statement:

To get the most out of Tailwind, you really should install it as a PostCSS plugin.


Everything the author has run into that you're calling out is from following the recommended installation guide in the Tailwind docs and will align with the experience of many new users.

Collapse
 
owenmelbz profile image
Owen Melbourne

Not really interested in any excuses tbf - The fact of the matter is sharing false information.

If people with less experience read that - they will repeat and take it for truth.

If a balanced argument is provided, they will be educated with both sides.

Collapse
 
souksyp profile image
Souk Syp.

The only thing I like about Tailwind is that you don’t have to switch between files while building a component for instance...

Collapse
 
sebring profile image
J. G. Sebring

This is what I love in Marko, but also Svelte or Vue.

Collapse
 
souksyp profile image
Souk Syp.

Svelte is awesome

Collapse
 
mikerogers0 profile image
Mike Rogers ✈️ • Edited

@zzoukk That is a really nice feature (React has the same appeal to me)! I have tried using a split tab in my code editor, but it never quite feels the same :/

Collapse
 
bogdaaamn profile image
Bogdan Covrig

Great article @mikerogers0 !!

I found I could glob import files via postcss-import-ext-glob, which made my index.css file much more maintainable

This was a game changer for me honestly. Not writing a wall of messy CSS it does bring me so much pleasure and makes writing CSS so much cooler.

Collapse
 
mikerogers0 profile image
Mike Rogers ✈️

Thank you @bogdaaamn !

I can't live without glob import now, it makes everything better!

Collapse
 
clandau profile image
Courtney

great article, Mike. I've learned a lot!

Collapse
 
mikerogers0 profile image
Mike Rogers ✈️

Thank you @clandau 🎉🙏

Collapse
 
zvizvi profile image
zvizvi

I made the following library just before someone referred me to this helpful post :)
github.com/zvizvi/freewindcss