styled-components v7
What's new in v7
v7 is in alpha. This release is under active development, and the docs will receive frequent updates over the next few weeks as internals are refined.
Install the prerelease from npm's @test dist-tag:
npm install styled-components@test
v7 is an architectural reform for the web and the start of a new chapter for styled-components/native. We replaced stylis with an in-house CSS parser, rewrote the native runtime from the ground up, and set a clear direction for native: the same CSS should feel the same everywhere, whether you render on web, iOS, or Android.
The React Native CanIUse page shows how far v7 has moved that goal already, and where there is still platform work to do.
The bottleneck now is funding. styled-components can help provide a universal React visual surface while strengthening React Native's styling ecosystem at the same time; recent upstream React Native PRs are already filling gaps around textAlignVertical, textDecorationStyle, textDecorationColor, and text decoration rendering. Donations and sponsorship make it possible to do that work outside of "passion time".
Highlights
- In-house CSS parser replaces stylis as the runtime engine. No more
:is()/:where()/:has()recursion bugs, no more silent breakage on modern at-rules. - Modern CSS on React Native.
@mediaand@containerqueries, viewport and container-query units, font-relative units, modern color spaces, relative-color syntax, the full Math L4 family, logical shorthands, gradients, and filters all work instyled.View\...``. See React Native gets modern CSS for the full surface and the compatibility matrix for per-feature status. - Selectors and combinators on React Native. Attribute selectors with every operator,
:not(<simple>),:has(<simple>), tree-structural pseudos, the four combinators between styled-component references, and the:hover/:focus/:pressed/:disabledpseudo-states. - Native animations by default.
transition,@keyframes, and@starting-stylerun on React Native through the built-inAnimated-based adapter, with no setup or peer dependency. An optional reanimated adapter is available behind one import (experimental; not heavily tested yet). createTheme()on native, with the same contract as web.<ThemeProvider>deep-merges nested themes so an inner override that touches one leaf keeps the siblings it inherited.- Dedicated
react-native-webbuild.styled-components/nativeships a smaller bundle for rn-web targets that defers to the browser forlight-dark()+prefers-color-schemerepaints, distinctdvh/svh/lvh/vi/vbresolution, wide-gamutoklch/oklab/lch/lab/color-mix(), and paint-timecalc()/clamp()/min()/max()against the real containing block. Webpack, Vite, and Metro web targets detect it automatically; other bundlers can importstyled-components/native/web-bridgedirectly. - Plugins subpath.
import { prefixPlugin, rtlPlugin, rscPlugin } from 'styled-components/plugins'. First-party RTL replacesstylis-plugin-rtl, and opt-inprefixPluginrestores vendor prefixing at React's browser support floor; custom plugins move to a narrowerSCPlugininterface. See Plugins moved to a dedicated subpath. extractCSS()reads the current stylesheet as plain text. Replaces the legacydisableCSSOMInjectiontoggle.- Global styles emit once. Mounting the same
createGlobalStylecomponent multiple times now emits its CSS only once. - Remapping CSS into native props via the function form of
.attrs((props, ast) => ...). Most useful for React Native libraries that style via props (e.g.react-native-svg's<Path fill="..." />,Image'stintColor, icon libraries). Details → - Polymorphic target autocomplete. With
<Component as="video" ...>, editors complete the target element's attributes such asloop,muted,controls, andposter. - Faster SSR at scale.
Peer dependency floors
reactandreact-dom≥ 19.0.0react-native≥ 0.85.0 (optional peer)react-native-reanimated≥ 4.0.0 (optional peer, only required if you opt into the reanimated animation adapter)
Older React or React Native projects should stay on v6.
Migrating from v6
Most v6 apps move to v7 by bumping the version, updating peers, and applying a few small changes. The list below is exhaustive; pick out the items that apply.
Install the current v7 prerelease with npm install styled-components@test.
Update peers
reactandreact-domto^19.react-nativeto^0.85if you use it.react-native-reanimatedto^4if you opt into the native animation adapter.- Drop
css-to-react-nativeif it was in yourpackage.jsononly for styled-components.
defaultProps is no longer honored
React 19 removed defaultProps from function components, so styled components can no longer inherit them either. Use .attrs() for prop defaults and <ThemeProvider> for default themes.
// Before (v6, no longer applies in v7) const Button = styled.button``; Button.defaultProps = { type: 'button' }; // After: object form always wins const Button = styled.button.attrs({ type: 'button' })``; // After: function form lets user props override const Button = styled.button.attrs<{ type?: string }>(p => ({ type: p.type ?? 'button', }))``;
disableCSSOMInjection and SC_DISABLE_SPEEDY removed; use extractCSS()
The browser build always uses the fast injection path. If you were toggling into a slower text-based mode to read the CSS as a string (for static-render pipelines, micro-frontend cloning, embedding into iframes or Shadow DOM), call the new extractCSS():