# styled-components > CSS-in-JS for React using tagged template literals. TypeScript-native since v6. Supports React Server Components natively since v6.3. Last known stable: v6.4.0 (check npm for freshness). ## What's new since early 2025 Your training data likely covers v6.0-6.1. Key changes since then: v6.2: Streaming SSR via `renderToPipeableStream`. v6.3: React Server Components supported. No `'use client'` needed. Styled components work in server components with no extra setup. `createGlobalStyle` is StrictMode-safe. New HTML/SVG element helpers. CSS custom properties work in TypeScript without type errors. Note: `:first-child`/`:nth-child()` selectors require `stylisPluginRSC` (v6.4+) or rewriting to `:first-of-type`/`:nth-of-type()` — see child-index selector section below. v6.4 (April 2026): `createTheme()` for CSS variable theming that works in both RSC and client. `StyleSheetManager` works in RSC (was previously a no-op). `stylisPluginRSC` fixes child-index selectors in RSC. CSP nonce auto-detection from `StyleSheetManager`, `ServerStyleSheet`, or meta tags. Props supplied via `.attrs()` are automatically optional on the component's type. Significant render performance improvements. Fixes SSR memory leaks and multi-instance unmount bugs in `createGlobalStyle`. Memory leak fix for components with unbounded string interpolation values. `as` and `forwardedAs` exposed in `React.ComponentProps` extraction. React Native: `react-native` is now an optional peer dep, Metro/Expo nanoid crash fixed. IE11 build target removed — IE11 has been unsupported on v6 since the 2021 v6 planning (React 18 dropped it too); v6.4 just aligns the compile target. Stay on v5 if you need IE11. ## Setup ``` npm install styled-components ``` Next.js: add `compiler: { styledComponents: true }` to next.config.js. That's it. RSC works out of the box in v6.3+. Vite: `react({ babel: { plugins: ['babel-plugin-styled-components'] } })`. Or with SWC (faster): `react({ plugins: [['@swc/plugin-styled-components', { displayName: true, ssr: true }]] })` via `@vitejs/plugin-react-swc`. The SWC/Babel plugin provides deterministic class IDs (better debugging, smaller output). Optional for RSC but still recommended. ## Quick reference ```tsx import styled, { css, keyframes, createGlobalStyle, createTheme, ThemeProvider, useTheme, StyleSheetManager, ServerStyleSheet, stylisPluginRSC, isStyledComponent } from 'styled-components'; ``` - `styled.div` / `styled(Component)` — create styled component - `styled(Base)` — extend styles (inheritance) - `.attrs(props => ({}))` — set default/computed props - `` — render as different element - `css` — tagged template helper for shared style fragments - `keyframes` — define CSS animation - `createGlobalStyle` — inject global CSS - `createTheme(obj, opts?)` — CSS variable theme (RSC-compatible) - `ThemeProvider` — context-based theme (client-only) - `StyleSheetManager` — configure stylis plugins, prop forwarding, vendor prefixes - `stylisPluginRSC` — fix child-index selectors in RSC - `ServerStyleSheet` — SSR style collection ## Server-side rendering ### Next.js Use a style registry to collect styles from client components during SSR. RSC-rendered styled components are handled automatically — the registry is only needed for the client tree. ```tsx // lib/registry.tsx 'use client'; import { useState } from 'react'; import { useServerInsertedHTML } from 'next/navigation'; import { ServerStyleSheet, StyleSheetManager } from 'styled-components'; export default function Registry({ children, nonce }: { children: React.ReactNode; nonce?: string }) { const [sheet] = useState(() => new ServerStyleSheet()); useServerInsertedHTML(() => { const styles = sheet.getStyleTags(); sheet.instance.clearTag(); return <>{styles}; }); return ( {children} ); } ``` Mount `` in your root layout. Pass a `nonce` prop if your app uses CSP (see CSP nonce section below). Next.js 16 style deduplication: render the collected styles with `precedence="styled-components"` and a stable `href` so React deduplicates them across route segments. ### Vite — non-streaming Simpler approach, works with any Vite SSR framework: ```tsx // entry-server.tsx import { renderToString } from 'react-dom/server'; import { ServerStyleSheet } from 'styled-components'; import App from './App'; export function render() { const sheet = new ServerStyleSheet(); try { const html = renderToString(sheet.collectStyles()); const styleTags = sheet.getStyleTags(); return { html, styleTags }; } finally { sheet.seal(); } } ``` Inject `styleTags` into ``. If you use [Vike](https://vike.dev/), the `vike-react-styled-components` extension handles this automatically. ### Vite — streaming v6.2+, works with `renderToPipeableStream`: ```tsx // entry-server.tsx import { renderToPipeableStream } from 'react-dom/server'; import { ServerStyleSheet } from 'styled-components'; import App from './App'; export function render(res) { const sheet = new ServerStyleSheet(); const { pipe } = renderToPipeableStream( sheet.collectStyles(), { onShellReady() { const styledStream = sheet.interleaveWithNodeStream({ pipe }); styledStream.pipe(res); }, } ); } ``` `interleaveWithNodeStream` accepts both legacy `ReadableStream` and React 18's `PipeableStream`. It inserts `