# styled-components

> Fast, expressive styling for React.

Latest version **6.5.3** (published 2026-08-15) · MIT license · 0 weekly downloads

## Install

```sh
npm install styled-components
pnpm add styled-components
yarn add styled-components
bun add styled-components
```

## Health

**Score 80/100 (A)** — status: active.

Positive: has types; esm support; no vulnerabilities; has provenance; recently updated; high maintenance score; high quality score; popular repo.

Warnings: low downloads.

## Facts

| | |
|---|---|
| Version | 6.5.3 |
| Published | 2026-08-15 |
| First published | 2016-08-16 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | bundled |
| Module format | ESM + CommonJS |
| Node | >= 16 |
| Dependencies | 4 |
| Unpacked size | 2 MB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| Provenance | attested (GitHub Actions) |
| GitHub stars | 41102 |
| Author | Glen Maddern |
| Maintainers | mxstbr, probablyup, philpl |
| Keywords | react, css, css-in-js, styled-components, styling |

## Links

- npm: https://www.npmjs.com/package/styled-components
- Repository: https://github.com/styled-components/styled-components
- Homepage: https://styled-components.com
- Issues: https://github.com/styled-components/styled-components/issues
- Funding: https://opencollective.com/styled-components
- npm.io page: https://npm.io/package/styled-components

## Dependencies (4)

- [stylis](https://npm.io/package/stylis.md) 4.3.6
- [csstype](https://npm.io/package/csstype.md) 3.2.3
- [css-to-react-native](https://npm.io/package/css-to-react-native.md) 3.2.0
- [@emotion/is-prop-valid](https://npm.io/package/@emotion/is-prop-valid.md) 1.4.0

## Alternatives

- [style-dictionary](https://npm.io/package/style-dictionary.md) — 2.0M weekly downloads
- [postcss-merge-idents](https://npm.io/package/postcss-merge-idents.md) — 1.7M weekly downloads
- [@fontsource/noto-sans](https://npm.io/package/@fontsource/noto-sans.md) — 93.0K weekly downloads
- [uglifycss](https://npm.io/package/uglifycss.md) — 71.6K weekly downloads
- [mat4-interpolate](https://npm.io/package/mat4-interpolate.md) — 23.3K weekly downloads

## Recent versions

- 6.5.3 (latest) — 2026-08-15
- 7.0.0-prerelease-20260908195050 (test) — 2026-09-08
- 6.6.0-prerelease-20260908162735 (6.x-test) — 2026-09-08
- 7.0.0-prerelease-20260908153432 — 2026-09-08
- 6.6.0-prerelease-20260905051044 — 2026-09-05
- 6.6.0-prerelease-20260817175248 — 2026-08-17
- 6.6.0-prerelease-20260815222953 — 2026-08-15
- 6.5.3-prerelease-20260815150702 — 2026-08-15
- 6.5.2 — 2026-08-11
- 6.5.2-prerelease-20260810214005 — 2026-08-10
- 7.0.0-prerelease-20260808041113 — 2026-08-08
- 7.0.0-prerelease-20260807223715 — 2026-08-07
- 6.5.1 — 2026-08-07
- 7.0.0-prerelease-20260806233720 — 2026-08-06
- 6.5.1-prerelease-20260806232123 — 2026-08-06
- … 442 more at https://npm.io/package/styled-components/versions

## README

<div align="center">
  <a href="https://styled-components.com">
    <img alt="styled-components" src="https://raw.githubusercontent.com/styled-components/brand/master/styled-components.png" height="150px" />
  </a>
</div>

<br />

<div align="center">
  <strong>Fast, expressive styling for React.</strong>
  <br />
  Server components, client components, streaming SSR, React Native—one API.
  <br />
  <br />
  <a href="https://www.npmjs.com/package/styled-components"><img src="https://img.shields.io/npm/dm/styled-components.svg" alt="npm downloads"></a>
  <a href="https://bundlephobia.com/result?p=styled-components" title="styled-components latest minified+gzip size"><img src="https://badgen.net/bundlephobia/minzip/styled-components" alt="gzip size"></a>
</div>

---

styled-components is largely maintained by one person. Please help fund the project for consistent long-term support and updates: [Open Collective](https://opencollective.com/styled-components)

---

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.
- **<13kB gzipped.** Small enough to disappear in your bundle. No build plugin required.

## Install

```sh
npm install styled-components
```

<details>
<summary>pnpm / yarn</summary>

```sh
pnpm add styled-components
```

```sh
yarn add styled-components
```

</details>

## 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<{ $primary?: boolean }>`
  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;
`;

<Button>Normal</Button>
<Button $primary>Primary</Button>
```

### 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 <a> tag with Button styles
<Button as="a" href="/home">Link Button</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;
  }
`;
```

### Animations

Define `@keyframes` once, reference them across components. Names are scoped automatically.

```tsx
import styled, { keyframes } from 'styled-components';

const rotate = keyframes`
  from { transform: rotate(0deg); }
  to { transform: rotate(360deg); }
`;

const Spinner = styled.div`
  animation: ${rotate} 1s linear infinite;
  width: 40px;
  height: 40px;
  border: 3px solid palevioletred;
  border-top-color: transparent;
  border-radius: 50%;
`;
```

### Theming

Share design tokens across your app via React context. Every styled component receives `props.theme`.

```tsx
import styled, { ThemeProvider } from 'styled-components';

const theme = {
  fg: 'palevioletred',
  bg: 'white',
};

const Card = styled.div`
  background: ${props => props.theme.bg};
  color: ${props => props.theme.fg};
  padding: 2em;
`;

<ThemeProvider theme={theme}>
  <Card>Themed content</Card>
</ThemeProvider>
```

### RSC-compatible themes

`createTheme` turns your tokens into CSS custom properties. Class name hashes stay stable across theme variants—no hydration mismatch when switching light/dark.

```tsx
import styled, { createTheme, ThemeProvider } from 'styled-components';

const { theme, GlobalStyle: ThemeVars } = createTheme({
  colors: {
    fg: 'palevioletred',
    bg: 'white',
  },
  space: {
    md: '1rem',
  },
});

const Card = styled.div`
  color: ${theme.colors.fg};       /* var(--sc-colors-fg, palevioletred) */
  background: ${theme.colors.bg};
  padding: ${theme.space.md};
`;

// Render <ThemeVars /> at the root to emit the CSS variable declarations
// Pass the theme to ThemeProvider for stable hashes
<ThemeProvider theme={theme}>
  <ThemeVars />
  <Card>Token-driven content</Card>
</ThemeProvider>
```

### Shared styles with `css`

Extract reusable style blocks to share across components or apply conditionally.

```tsx
import styled, { css } from 'styled-components';

const truncate = css`
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
`;

const Label = styled.span`
  ${truncate}
  max-width: 200px;
`;
```

### Styling third-party components

Wrap any component that accepts a `className` prop.

```tsx
import styled from 'styled-components';
import { Link } from 'react-router-dom';

const StyledLink = styled(Link)`
  color: palevioletred;
  text-decoration: none;

  &:hover {
    text-decoration: underline;
  }
`;
```

### Global styles

Inject app-wide CSS like resets and font faces. Supports theming and dynamic updates.

```tsx
import { createGlobalStyle } from 'styled-components';

const GlobalStyle = createGlobalStyle`
  body {
    margin: 0;
    font-family: system-ui, sans-serif;
  }
`;

// Render <GlobalStyle /> at the root of your app
```

### Attrs

Set default or static HTML attributes so consumers don't have to.

```tsx
const PasswordInput = styled.input.attrs({
  type: 'password',
  placeholder: 'Enter password',
})`
  border: 1px solid #ccc;
  padding: 0.5em;
`;
```

## Documentation

- [Getting started](https://styled-components.com/docs/basics)
- [API reference](https://styled-components.com/docs/api)
- [Server-side rendering](https://styled-components.com/docs/advanced#server-side-rendering)
- [React Server Components](https://styled-components.com/docs/advanced#react-server-components)
- [Theming](https://styled-components.com/docs/advanced#theming)
- [React Native](https://styled-components.com/docs/basics#react-native)

## Community

[Contributing guidelines](./CONTRIBUTING.md) | [Code of Conduct](./CODE_OF_CONDUCT.md) | [awesome-styled-components](https://github.com/styled-components/awesome-styled-components)

## Contributors

This project exists thanks to all the people who contribute.

<a href="https://github.com/styled-components/styled-components/graphs/contributors"><img src="https://opencollective.com/styled-components/contributors.svg?width=890" /></a>

## Backers

Thank you to all our backers! [[Become a backer](https://opencollective.com/styled-components#backer)]

<a href="https://opencollective.com/styled-components#backers" target="_blank"><img src="https://opencollective.com/styled-components/backers.svg?width=890"></a>

## Sponsors

Support this project by becoming a sponsor. [[Become a sponsor](https://opencollective.com/styled-components#sponsor)]

<a href="https://opencollective.com/styled-components#sponsors" target="_blank"><img src="https://opencollective.com/styled-components/sponsors.svg?width=890"></a>

## Acknowledgements

This project builds on earlier work by Charlie Somerville, Nik Graf, Sunil Pai, Michael Chan, Andrey Popp, Jed Watson, and Andrey Sitnik. Special thanks to [@okonet](https://github.com/okonet) for the logo.

## License

Licensed under the MIT License, Copyright © 2016-present styled-components contributors. See [LICENSE](./LICENSE) for details.

---
_Source: https://npm.io/package/styled-components · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
