styled-components /styled-components
Fast, expressive styling for React. Server components, client components, streaming SSR, React Native—one API.
★ 41,048⑂ 2,606👁 367⑃ 1,525● 3,027▤ 268◈ 93
41,048
stars
+0
2,606
forks
367
watchers
1,525
prs
3,027
issues
268
releases
93
discussions
README
Fast, expressive styling for React.
Server components, client components, streaming SSR, React Native: one API.
---
styled-components is largely maintained by one person. Please help fund the project for consistent long-term support and updates: Open Collective
---
Style React components with real CSS, scoped automatically and delivered only when needed. No class name juggling, no separate files, no build step required.
- Works everywhere React runs. Server components, client components, streaming SSR, and React Native: same API, automatic runtime detection.
- Full CSS, no compromises. Media queries, pseudo-selectors, nesting, keyframes, global styles. If CSS supports it, so does styled-components.
- TypeScript-first. Built-in types ship with the package. Props flow through to your styles with full inference: no @types install, no manual generics.
- Small. The badge above shows the current minified and gzipped size. No build plugin required.
Install
sh
npm install styled-components
pnpm / yarn
sh
pnpm add styled-components
sh
yarn add styled-components
Quick examples
Dynamic props
Vary styles based on component props. Prefix transient props with $ to keep them off the DOM.
tsx
import styled from 'styled-components';
const Button = styled.button
background: ${props = (props.$primary ? 'palevioletred' : 'white')};
color: ${props = (props.$primary ? 'white' : 'palevioletred')};
font-size: 1em;
padding: 0.25em 1em;
border: 2px solid palevioletred;
border-radius: 3px;
;
Normal
Primary
Extending styles
Build variants on top of existing styled components.
tsx
const TomatoButton = styled(Button)
background: tomato;
color: white;
border-color: tomato;
;
Polymorphic as prop
Swap the rendered element without changing styles.
tsx
// Renders a tag with Button styles
Link Button
Pseudos and nesting
Use & to reference the component's generated class name; works with pseudo-classes, pseudo-elements, and nested selectors.
tsx
const Input = styled.input
border: 1px solid ccc;
border-radius: 4px;
padding: 0.5em;
&:focus {
border-color: palevioletred;
outline: none;
}
&::placeholder {
color: aaa;
}
;
Vendor prefixes
CSS is emitted unprefixed by default. To support browsers that require prefixes for CSS such as appearance, user-select, or ::placeholder, add the opt-in prefixPlugin at the relevant subtree:
tsx
import { StyleSheetManager } from 'styled-components';
import { prefixPlugin } from 'styled-components/plugins';
;
The included prefix set targets Chrome 45, Firefox 36, Safari and iOS 9, and Edge 12, matching the browser floor for the JavaScript APIs required by React. For a different set, declare both the prefixed and standard forms yourself, or extend the plugin with one of your own:
tsx
import { StyleSheetManager } from 'styled-components';
import { prefixPlugin } from 'styled-components/plugins';
import type { SCPlugin } from 'styled-comTop issues
#57676.4.3: `PolymorphicCallProps` rewrite causes 57× more `ComponentPropsWithRef` instantiations, +1.6 GB tsc heap in our app10 comments · 2026-07-02#5808inline <style> tags get removed by <Suspense> streaming, making styles disappear7 comments · 2026-09-03#4350OOM during typecheking in 6.1.137 comments · 2024-09-09#5838stylisPluginRSC not working on Nextjs navigations5 comments · 2026-10-16#4305Regression: `typeof` on a styled component returns incompatible type5 comments · 2024-05-07#5788[6.4.x / 6.5.0] Rules of Hooks violation in dev mode when styled component re-renders with unchanged style props (regression from 6.4.0)4 comments · 2026-08-06#5737SSR hydration mismatch (all class names differ between server and client) introduced in 6.3.12 with webpack + nodeExternals3 comments · 2026-04-30#5613Line comments are not supported in multiline style declarations3 comments · 2025-10-21
Discussions
#5673Any interest in integrating WyW-in-JS for a zero runtime option?0 comments · 2026-02-21#5657Is styled-components in maintenance mode?1 comments · 2026-02-02#5619New Philosofy0 comments · 2025-12-19#5568Library entering maintenance mode1 comments · 2025-03-23#5515Integration with tailwindcss?1 comments · 2025-01-01#4366React 16 compatibility with styled-components0 comments · 2024-11-01#4344Is this good approach? -- <style>{` ${Comp} {....} `}</style>0 comments · 2024-08-23#4330Is there any update roadmap?1 comments · 2024-07-05
Latest release
[email protected] [email protected] 2026-10-12Minor Changes
- 7ce6aea: Added a StyledComponent type for annotating explicitly-typed styled component exports.
Packages that emit their own declaration files, including any project using isolatedDeclarations, must annotate every exported styled component, and there was no public type for it: consumers reached into internal paths or hand-assembled one that dropped members like a wrapped component's hoisted statics.
StyledComponent is exported from the web and native entries. Name the target and props as you passed them to styled:
tsx
import styled, { type StyledComponent } from 'st