styled-components
6.6.0 · 12 Oct 2026MIT14.8M / weekRepositoryHomepagenpmAtom feed
2.4.1 is the newest release of 2.x.
In short
2 new5 fixed
Release note
A smaller, faster drop-in upgrade with even more features
Read the full changelog in prose over here on Medium: medium.com/styled-components/announcing-v2-f01e…
It's been a long time (ehem, forever) that we've written release notes, so let's start with a detailed one for v2.
All our documentation is now hosted on a nice website, so if you're having trouble with v2, or learning styled-components in general, check our website: styled-components.com
Breaking Changes
PostCSS was replaced with Stylis
Instead of PostCSS we're now using Stylis for our CSS processing needs. By doing so we managed to cut our bundle size (min+gzip) from ~24kB down to ~12kB, meaning you’ll now ship a lot less code to your users!
Server Side Rendering
We added an API for concurrent server side rendering including rehydration on the client. The API is lean and simple:
import { renderToString } from 'react-dom/server'
import { ServerStyleSheet } from 'styled-components'
const sheet = new ServerStyleSheet()
const html = renderToString(sheet.collectStyles(<YourApp />))
const css = sheet.getStyleTags()Learn more in our docs: styled-components.com/docs/advanced
Upgrade css-to-react-native (React Native)
You'll now need to add units to your React Native shorthand styles, but on the up-side: We now support percentage-units!
A codemod is available: github.com/styled-components/styled-components-…
Added
.attrs
You can now attach some props directly to a Styled Component. When you use functions as attributes, we'll pass in the component's props, so you can write some more complex logic, without resorting to wrapping an entire component.
const ExternalLink = styled.a.attrs({
target: '_blank',
rel: 'nofollow',
style: props => ({
background: `${props.hue},
${50 + props.luminosity / 2},
${props.luminosity}`
})
}) // ....extend and .withComponent helpers
The .extend method allows you to create a new Styled Component based on another one, combining the rules into a single new class.
const Heading = styled.h1`
font-size: 2.5rem;
font-weight: bold;
margin: 2rem;
text-align: center;
`
const MarketingHeading = Heading.extend`
background: midnightblue;
color: white;
&:hover { text-shadow: 0 0 4px white; }
`The .withComponent method can be used to create a new Styled Component based on another one, but with a different tag or wrapped component.
Chain both methods for unlimited POWER!...
Contextual Overrides
You can now use Styled Components as interpolations and we'll swap them out for their classnames:
const Link = styled.a`
color: inherit;
text-decoration: none;
&:hover, &:active {
text-decoration: underline;
}
`
const P = styled.p`
${ Link } {
text-decoration: underline;
}
`Changed
Fix defaultProps used instead of ThemeProvider on first render
Prevent leakage of the
innerRefprop to wrapped child; under the hood it is converted into a normal ReactrefAdd hoisting static (non-React) properties for withTheme HOC
Add
innerRefsupport to withTheme HOCFix Theme context for StyledComponent for IE <10
Fix
setNativePropsin StyledNativeComponentFix
refbeing passed to Stateless Functional Components in StyledNativeComponent
A whole project to check? Paste its package.json in the dependency check: every deprecated, outdated or vulnerable dependency, with what to upgrade to. Free, no account.