Skip to main content
CSS-in-JS lets you write CSS directly in your JavaScript or TypeScript files, typically co-located with the component that uses it.
Many CSS-in-JS libraries that rely on runtime JavaScript are not compatible with React Server Components. You can only use CSS-in-JS in Client Components. Check your library’s documentation for Server Component support.

Supported libraries

The following libraries are known to work with the App Router Client Components:

styled-components

Tagged template literal API with full theming support.

Emotion

High-performance CSS-in-JS library with css prop and styled API.

Kuma UI

Zero-runtime utility-first CSS-in-JS.

vanilla-extract

Type-safe, zero-runtime CSS-in-JS.

styled-components

Installation

Configuration

Enable styled-components in next.config.js to activate the built-in Babel plugin for server-side rendering:
next.config.js

Registry

To use styled-components with the App Router, you need to set up a client-side style registry. This collects styles generated during a render and flushes them into the <head> of the document.
lib/registry.tsx
Wrap your root layout’s children with the registry:
app/layout.tsx

Usage

Use styled-components only in Client Components:
app/components/Button.tsx

Emotion

Installation

Registry

Emotion requires a similar server-side registry to styled-components:
lib/registry.tsx

Usage

Use Emotion in Client Components:
app/components/Card.tsx

Server Components

CSS-in-JS libraries that depend on runtime style injection cannot be used in Server Components. For Server Components, use:
  • CSS Modules — zero runtime, statically extracted at build time.
  • Tailwind CSS — utility classes with no JavaScript runtime.
  • Sass — pre-processed CSS compiled at build time.