Emotion is a CSS-in-JS library. It lets you write real CSS — the same selectors, media queries, and pseudo-classes you already know — but inside your JavaScript files, scoped to a component. If you like CSS but hate managing class names and global stylesheets, Emotion is the middle ground.
There are two ways to use it. The css prop lets you style any element inline:
/** @jsxImportSource @emotion/react */ import { css } from "@emotion/react" ;
function Card ( ) { return ( < div css = { css ` padding: 24px; border-radius: 12px; background: #fff; box-shadow: 0 2px 8px rgba(0, 0, 0, 0.1); &:hover { transform: translateY(-2px); } ` } > Hover me </ div > ) ; }
Enter fullscreen mode
Exit fullscreen mode
Or use styled to create reusable components that look like normal HTML tags:
import styled from "@emotion/styled" ;
const Button = styled . button ` padding: 10px 20px; background: ${(props) => (props.primary ? "#0070f3" : "#eee")}; color: ${(props) => (props.primary ?…