talira

CSS-in-JS library designed for high performance style composition

open sourceMITself-hostablefree

Emotion is a CSS-in-JS library for writing styles in JavaScript, as template strings or objects, with predictable composition that avoids specificity problems, source maps and labels for debugging, and caching for performance in production. The framework-agnostic @emotion/css package gives you a css function that returns class names; for React, @emotion/react adds a css prop with theming and zero-configuration server-side rendering, and @emotion/styled the styled.div API. A Babel plugin, ESLint plugins and testing utilities come with it. It is MIT-licensed and maintained by its community with Open Collective backers and sponsors.

Problems it solves

  • keep each React component's styles in the same file as the component instead of a global stylesheet
  • style components based on their props without juggling class names
  • avoid CSS specificity fights when composing styles from several components
  • a theme object with our colours and spacing that every styled component can read
  • server-render styled React components without extra setup
  • generate scoped class names from JavaScript in a project that doesn't use React
  • see which component a generated class came from while debugging styles in devtools
  • write nested selectors and media queries in JavaScript styles, with vendor prefixes added for me
  • snapshot-test the styles my components render

Features

  • string and object styles
  • framework-agnostic css function and cx composition (@emotion/css)
  • css prop for React elements, with access to the theme (@emotion/react)
  • styled.div style API for creating components (@emotion/styled)
  • theming with a ThemeProvider
  • server-side rendering with zero configuration for @emotion/react
  • global styles, keyframes, nested selectors and media queries
  • automatic vendor prefixing
  • source maps and labels showing which component a class came from
  • Babel plugin for minification and optimisation
View 1 more
  • ESLint plugins and Jest testing utilities

Alternatives

The same job

These do what Emotion does.

  1. styled-components Fast, expressive styling for React. Server components, client components, streaming SSR, React Native, all one API.
  2. StyleX The expressive, type-safe, composable, predictable and themeable styling system for ambitious interfaces
  3. goober A less than 1KB css-in-js solution
  4. Panda CSS Universal, type-safe, CSS-in-JS framework for design systems
  5. vanilla-extract Zero-runtime Stylesheets-in-TypeScript

Compare Emotion with the top 3