Emotion is my favorite CSS-in-JS library.
It's easy to define style classes (both inline or in separate files), compose them in powerful ways with the cx
utility, sprinkle them into React components using the standard className
attribute. There's no need to ever modify your markup/JSX to apply styles (as it should be!). Plus you only need to install a single module (yarn add emotion
) and there's no complicated Babel plugin or config file to set up.
I'm currently building a Tailwind-style CSS-in-JS utility styling library (join my newsletter at the bottom of this page to stay updated!) and Emotion provides the perfect layer of abstraction to build upon.
Unfortunately everything I just said only applies to the vanilla emotion
module (https://emotion.sh/docs/emotion), not the inexplicably-named @emotion/core
module. @emotion/core
is the React-focused Emotion wrapper that gives you some extra goodies, like server-side rendering and theming.