

5 CSS-in-JS Frameworks to use in 2021
source link: https://blog.openreplay.com/5-css-in-js-frameworks-to-use-in-2021
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.

As web development continues massive evolving, new ways of doing things emerge, and communities get built around them. Handling frontend development with JS frameworks, styling components have been all about having separately dedicated stylesheets for each component which are now applied to the DOM.
Introduction
CSS can be really exhausting for developers, maintaining styles across components and context switching can become a chore, you can also relate to this if you have spent some time trying to center a div or a button before. Developers who primarily work with JavaScript started to innovate around styling and asking what if it can also be done in JS.
CSS-in-JS is a new approach to styling using JavaScript to style components in-line, on compile, the JS is parsed and CSS rules are generated and pushed to the DOM. This means you do not really have to carry the burden of the CSS learning curve, neither do you need to fully understand it as it is now totally abstracted for you. This approach promises to be more maintainable, easier to use (as you stick to the JS you already know) and some even have special features built to enhance CSS.
In today’s post, we will be looking at a few of these CSS-in-JS frameworks you can try out in your workflow right away.
Styled Components
This is the most popular CSS-in-JS library that currently exists and the term CSS-in-JS was also made very popular by Styled Components. With widespread usage, over 35,000 stars on GitHub with over 10m projects using it per month Styled Components lets you define CSS styles inline using ES6 template literals. Popular in the React community for styling React components easily. This is how easy a button is styled:
The style definition would look like this:
Styled Components comes with a lot of advantages asides we general ones we already mentioned above, you can do selector nesting, just like with SASS. You also never need to worry about class name bugs as it generates unique class names automatically and manages them as they go in and out of the DOM.
Emotion
The first special thing about Emotion as a CSS-in-JS library is that is framework agnostic so you can use it in Vue and Angular projects as well as React too. With over 13,000 stars on GitHub Emotion is a very flexible library that is built on other CSS-in-JS libraries and another great thing about it is how it is predictable so even with little knowledge of CSS, you can start using it without any issues. It has a really cool documentation, the vue-style that you are probably already familiar with and is very performant.
A hover button in Emotion looks like this:
Open Source Session Replay
Debugging a web application in production may be challenging and time-consuming. OpenReplay is an Open-source alternative to FullStory, LogRocket and Hotjar. It allows you to monitor and replay everything your users do and shows how your app behaves for every issue. It’s like having your browser’s inspector open while looking over your user’s shoulder. OpenReplay is the only open-source alternative currently available.

Happy debugging, for modern frontend teams - Start monitoring your web app for free.
Stitches

This is a very interesting one, with almost 4,000 stars on GitHub Stitches is a CSS-in-JS library that runs in near-zero runtime. It supports server-side rendering and has variants support. Basically, CSS was re-imagined as a JS library with stitches. It is also framework agnostic so you can use it with any frontend development library. It ships with smart tokens and even custom CSS properties.
With Stitches, you do not have to download an entire library because it does style injection. With a fully-typed API, token-aware properties, and custom utils, Stitches offers a fun and intuitive experience all-round.
A simple button is created like this:
Radium

Radium took a kind of radical approach, eliminating CSS totally for inline styles and making all of those styles global. This basically provides us with scoped styling without using selectors, eliminating dead code or chances of repeattition and being totally expressive. You might say inline styles are limited by default, that is correct but Radium offers a standard interface that deals with issues like media queries and browser or mouse states like click or hover.
A button in Radium looks like this:
It was built for React applications, most of the CSS-in-JS libraries have dedicated React libraries too.
JSS is a CSS abstraction in JavaScript, it dynamically outputs rules based on component state. It is super lightweight and one great thing about it is integrations, it has a React integration, a Styled Component integration and a lot of plugins too. Remember how some CSS-in-JS generates styles and injects them inline in the DOM, JSS does it the old fashioned way output a master stylesheet before injecting it. There are a lot of useful plugins you can use to achieve the functionality available in other CSS-in-JS libraries like nesting, global selectors, plugin isolation etc.
A button looks like this:
Conclusion
We have gotten acquainted with the concept of CSS-in-JS and how it can be useful to us in our workflow. We also took a look at a few CSS-in-JS libraries we can start using today. You can follow the State of CSS survey here where thousands of developers share their feeedback every year. Which is your favourite and why?
Recommend
-
19
Photo by C Dustin on Unsplas...
-
4
Introduction This article covers: Customizing the deployed BootStrap How to switch to a different CSS Framework The new Scoped CSS functionalityPlease note that this article is aimed at pr...
-
7
CSS Frameworks, hype and dogmatism25th January, 2021Some notes on the dogmatism and gatekeeping themes of Tech Twitter and how they can generate often incorrect and naive statements—specifically about framewor...
-
6
Apr 22nd, 2019Hasty Treat - CSS Frameworks👇 Download Show✏️ Edit Show Notes
-
3
Jamstack Developers’ Favorite Frameworks of 2021 Laurie Voss on Oct 12, 2021 Take your JavaScript to the next level at . ...
-
5
Best CSS Frameworks in 2021 Bootstrap Foundation Bulma Tailwind CSS UI Kit Milligram Materialize CSS 1️⃣ Bootstrap Quickly design...
-
5
I must admit, when I first got introduced to CSS, I hated the idea of using CSS frameworks. I saw it as a lazy way to go around a challenge. But along the way, as I played around with a few frameworks, I realized they save you the he...
-
9
How to Make a Component That Supports Multiple Frameworks in a Monorepo Rob Levin on Jan 5, 2022 Your mission — should you decid...
-
6
The State of CSS shows which five...
-
9
This is the third part of the Top CSS Frameworks of 2022 report. Read the previous reports about the file sizes and
About Joyk
Aggregate valuable and interesting links.
Joyk means Joy of geeK