# 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.7.0 (check npm for freshness). ## Recent releases 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: in v6, `: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–July 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. Fixes SSR memory leaks, multi-instance unmount bugs in `createGlobalStyle`, and unbounded string interpolation memory leaks. `as` and `forwardedAs` exposed in `React.ComponentProps` extraction. React Native: `react-native` is an optional peer dep, Metro/Expo nanoid crash fixed. IE11 build target removed (stay on v5 if you need IE11). v6.5–v6.7 (August–November 2026): `StyledComponent` exported on web and native for explicit export annotations and `isolatedDeclarations`, plus faster consumer type-checking. Style interpolations run on every render (fixes hook-order crashes when hooks are called inside an interpolation; wrap in `React.memo` for props-equal bailout). RSC component and `createGlobalStyle` styles survive `` reveals and sibling route transitions. `.attrs()` applies its default even when a prop is explicitly passed as `undefined`. v6.7 adds `configureServerStyles({ stylisPlugins })` for process-wide RSC plugins (such as `stylisPluginRSC`), fixes React 18/Next.js 13.5–14 HTML-escaping inside RSC `` substrings and HTML-escapes nonce values to prevent style-tag breakout, and malformed interpolated values stay contained inside their own statement. - Unitless numbers in object styles include `gridArea`, `lineClamp`, `fontSizeAdjust`, `hyphenateLimitChars`, `initialLetter`, `mathDepth`, `shapeImageThreshold`, and `maskBorder*`. - `StyledComponent` is exported on web and native for explicit export annotations and `isolatedDeclarations` (also in v6.5+). - Polymorphic `as` targets drive editor attribute completion: `` completes `loop`, `muted`, `controls`, `poster`, and the other video attributes. Runtime behavior is unchanged. ## 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 (v6.7 stable) ```tsx import styled, { css, keyframes, createGlobalStyle, createTheme, ThemeProvider, useTheme, StyleSheetManager, ServerStyleSheet, configureServerStyles, stylisPluginRSC, isStyledComponent, type StyledComponent } from 'styled-components'; ``` - `styled.div` / `styled(Component)`: create styled component - `styled(Base)`: extend styles (inheritance) - `.attrs(props => ({}))`: set default/computed props - `.attrs((props, ast) => ({}))`: v7+ second arg lifts compiled styles or typed theme paths into props (`ast.pop('color')`, `ast.peek('palette.brand', fallback)`) - ``: 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; also native in v7+) - `ThemeProvider`: context-based theme (client-only on web; deep-merges on native in v7+) - `StyleSheetManager`: configure `stylisPlugins` (v6) / `plugins` (v7), `namespace`, prop forwarding, nonce - `configureServerStyles`: process-wide RSC defaults (`{ stylisPlugins }` in v6.7, `{ plugins, namespace }` in v7) - `stylisPluginRSC`: fix child-index selectors in v6 RSC (removed in v7, where styles route through the registry) - `ServerStyleSheet`: SSR style collection (and RSC style collection in v7) - `StyledComponent`: explicit export annotation type (v6.5+ / v7) ## Server-side rendering ### Next.js Use a style registry to collect styles during SSR. In v7, the registry collects styles for BOTH server components and client components (wrap `` in your root layout so even a styled `` or `` sits inside it). In v6.3–v6.7, RSC emits inline `