Originally posted at michaelzanggl.com. Subscribe to my newsletter to never miss out on new content.
CSS frameworks are a great way to quickstart a project. They let you focus on your application rather than the design. This is especially great if you are not a designer and don't have one in your team.
But over time you need customization and this is where the fight over specificity, the fight against the framework begins.
This is of course nothing new, people have argued over this for a long long time.
The thing though is, that this was actually not such a big problem before. Sure you maybe needed some !important
and other ugly hacks here and there, but it was at least not hard to know where to add those overrides.
Nowadays, some small class you want to override lives inside a component of the framework, isolated away. The class names are generated automatically and what was once an easy hack away to change became incredibly tedious to override.
In Vuetify I find myself doing this
.list-tile:hover >>> .v-list__tile {
background: transparent;
}
v-list__tile
being a class inside one of Vuetify's components. If this internally used class name gets changed, will that even be mentioned in the upgrade guide?
Another thing is the API of modern CSS frameworks. Bootstrap's APIs and CSS classes were very simple to keep in your head. But today, whenever I develop using such a framework, I have to have the documentation of Vuetify, Material UI or whatever open at all times, getting ready to copy paste 50 lines of code for a simple dialog. There is no way I will remember all the props, scopes, events, etc. of each component. This whole copy paste action also takes away the fun to be honest.
Ever since I started using the low level utility-first CSS framework Tailwind, working with anything else feels unproductive. I've written a blog post on it here. Sure, at first you need to look at the documentation, but it's API is predictable and easy to remember, also there are tools for autocompletion available. The best thing is that it is completely framework agnostic. No new API to learn just because you decide to use React over Vue in your next project.
What are your thoughts on modern CSS frameworks? Do you enjoy using them?
Top comments (28)
I want a banana 🍌, I know.. I'll import the jungle 🍌🦍🐦💦🌴. That's my feels towards CSS frameworks, I used to be the opposite.
I was a big css framework person for a long time. But I’ve started writing all css from scratch for my side projects and I feel so much power! Plus, it’s nice to remember how things actually work rather than relying on framework components.
This. Writing your own css is so much more satisfying and CLEAN. Having to hack away at a framework to overwrite countless styles is so unproductive and leads to some serious bloat.
When I do need to do some quick scaffolding, I've been using modules from Bass CSS recently for side projects. It's very low level and modular so you can include just the pieces you want to get you past some of the basic boilerplate stuff like typography.
I think you should invest in smaller compile time only frameworks, such as a scss grid (do we even need grids anyway?) Maybe something lean and minimal to kick-start. But after that do it yourself.
Yes, the future of "CSS Frameworks" are Web Components that expose Named Parts for author styling.
Tailwind is great. I prefer Bulma though.
I think as with most things, it's circumstantial. Also opting for a less do all the things framework is beneficial. Bulma seems a reasonable balance between useful stuff and not overly in the way. Similarly, buefy for some starting point Vue components that can still be pretty easily styled however you wish.
My colleague just started using tailwind with buefy and says it's great, haven't tried that yet myself.
But yeah.. entirely depends on the circumstances I think. Are you building something totally custom? Plain vanilla css or something like tailwind is probably a good option, prototyping a more do everything framework will probably save time. Honestly though tailwind largely seems like mostly a prototyping tool too...
I agree on Bulma. I'm currently working on a project that uses the Buefy component lib (based on Bulma). For the most part, Bulma stays out of the way until you actually want to use its styles.
material-ui for react seems ok, even if you have to override some things, but yeah, reading documentation for API and how it should be used is crucial part of it. Recently started to use styled components and I like it a lot. Writing my own styles without css frameworks.
Ever try shadow DOM? It's been liberating for me. Nowadays I just apply styles as needed - no need for baroque classes or
!important
.Will give it a try!
Emotion and react has been made incredibly flexible and extendable, but agreed that css frameworks are more trouble than they are worth. How long does it take to code a good looking button and import it everywhere?
There are upsides to using a CSS library such as Material, which applies best practices out front and doesn't require the use of the entire library. Often I find it to be the fault of designer/developer teams who find it easier to import an entire framework into an app when only 15% to 40% of it gets used.
I found that together with LitElement created web components I can choose specifically what I want to include as shared CSS across all components and adding only what I need keeping the components light while enjoying shadowDOM isolation and reusability. It's great to have options, but I'm very sensitive about just how many bytes we have to deliver to a screen.
As you said, Bootstrap-like frameworks are a good alternative when you don't have a designer in the project or even when you don't have time to create a styleguide properly.
After thinking a lot about the need of those big CSS frameworks in my projects, these ones crossed my path:
As a front-ender, I love to create the styles and optimize it until it breaks. Excluding Bulma and Primer, the above are considered micro-frameworks or even CSS starter packs; and they helped me to save time while developing.