styled-components
Visual primitives for the component age. Use the best bits of ES6 and CSS to style your apps without stress
Last updated 22 days ago by probablyup .
MIT · Repository · Bugs · Original npm · Tarball · package.json
$ cnpm install styled-components 
SYNC missed versions from official npm registry.
styled-components

Visual primitives for the component age. Use the best bits of ES6 and CSS to style your apps without stress ????

downloads: 600k/month Join the community on Spectrum gzip size module formats: umd, cjs, esm


⚠️ CANARY: This is the canary branch of styled-components. It is published under the @alpha tag on npm and contains new features and changes for the next major version.

Utilising tagged template literals (a recent addition to JavaScript) and the power of CSS, styled-components allows you to write actual CSS code to style your components. It also removes the mapping between components and styles – using components as a low-level styling construct could not be easier!

styled-components is compatible with both React (for web) and React Native – meaning it's the perfect choice even for truly universal apps! See the documentation about React Native for more information.

Supported by Front End Center. Thank you for making this possible!

Upgrading from v4

  1. npm install styled-components@alpha react@^16.8 react-dom@^16.8 react-is@^16.8
  2. ??
  3. Profit!

Note that integrations like jest-styled-components that make use of internals will need to be updated to work with v5 and likely will not work properly during the alpha/beta period.

Docs

See the documentation at styled-components.com/docs for more information about using styled-components!

Quicklinks to some of the most-visited pages:

Example

import React from 'react';

import styled from 'styled-components';

// Create a <Title> react component that renders an <h1> which is
// centered, palevioletred and sized at 1.5em
const Title = styled.h1`
  font-size: 1.5em;
  text-align: center;
  color: palevioletred;
`;

// Create a <Wrapper> react component that renders a <section> with
// some padding and a papayawhip background
const Wrapper = styled.section`
  padding: 4em;
  background: papayawhip;
`;

// Use them like any other React component – except they're styled!
<Wrapper>
  <Title>Hello World, this is my first styled component!</Title>
</Wrapper>

This is what you'll see in your browser:

Screenshot of the above code ran in a browser

Babel Macro

If you're using tooling that has babel-plugin-macros set up, you can switch to the styled-components/macro import path instead to gain the effects of the babel plugin without further setup.

import styled from 'styled-components/macro';

// A static className will be generated for Title (important for SSR)
const Title = styled.h1`
  font-size: 1.5em;
  text-align: center;
  color: palevioletred;
`;

If you wish to provide configuration options to the babel plugin similar to how you would in a .babelrc, see this guide. The config name is "styledComponents".

Built with styled-components

A lot of hard work goes into community libraries, projects, and guides. A lot of them make it easier to get started or help you with your next project! There’s also a whole lot of interesting apps and sites that people have built using styled-components.

Make sure to head over to awesome-styled-components to see them all! And please contribute and add your own work to the list so others can find it.

Contributing

If you want to contribute to styled-components please see our contributing and community guidelines, they'll help you get set up locally and explain the whole process.

Please also note that all repositories under the styled-components organization follow our Code of Conduct, make sure to review and follow it.

Badge

Let everyone know you're using styled-componentsstyle: styled-components

[![style: styled-components](https://img.shields.io/badge/style-%F0%9F%92%85%20styled--components-orange.svg?colorB=daa357&colorA=db748e)](https://github.com/styled-components/styled-components)

Contributors

This project exists thanks to all the people who contribute. [Contribute].

Backers

Thank you to all our backers! ???? [Become a backer]

Sponsors

Support this project by becoming a sponsor. Your logo will show up here with a link to your website. [Become a sponsor]

License

Licensed under the MIT License, Copyright © 2016-present Glen Maddern and Maximilian Stoiber.

See LICENSE for more information.

Acknowledgements

This project builds on a long line of earlier work by clever folks all around the world. We'd like to thank Charlie Somerville, Nik Graf, Sunil Pai, Michael Chan, Andrey Popp, Jed Watson & Andrey Sitnik who contributed ideas, code or inspiration.

Special thanks to @okonet for the fantastic logo.

Current Tags

  • 5.0.0-beta.9                                ...           beta (22 days ago)
  • 4.4.0                                ...           latest (22 days ago)
  • 4.0.3-0                                ...           sourcemap (a year ago)
  • 4.4.0-reactnativewebfix                                ...           test (5 days ago)

246 Versions

  • 4.4.0-reactnativewebfix                                ...           5 days ago
  • 4.4.0                                ...           22 days ago
  • 5.0.0-beta.9                                ...           22 days ago
  • 5.0.0-beta.8-groupsizefix                                ...           2 months ago
  • 5.0.0-beta.8                                ...           3 months ago
  • 5.0.0-beta.6-ej4                                ...           4 months ago
  • 5.0.0-beta.6-ej3                                ...           4 months ago
  • 5.0.0-beta.6-ej2                                ...           4 months ago
  • 5.0.0-beta.6-ej1                                ...           4 months ago
  • 5.0.0-beta.6-ej                                ...           4 months ago
  • 5.0.0-beta.6                                ...           4 months ago
  • 5.0.0-beta.5-removefoldedcomponentids                                ...           4 months ago
  • 5.0.0-beta.5-ej2                                ...           4 months ago
  • 5.0.0-beta.5                                ...           4 months ago
  • 5.0.0-beta.4                                ...           4 months ago
  • 4.3.2                                ...           4 months ago
  • 5.0.0-beta.3                                ...           4 months ago
  • 5.0.0-beta.2                                ...           4 months ago
  • 5.0.0-beta.1                                ...           4 months ago
  • 5.0.0-beta.0                                ...           4 months ago
  • 5.0.0-alpha.2                                ...           4 months ago
  • 5.0.0-alpha.1                                ...           4 months ago
  • 5.0.0-alpha.0                                ...           4 months ago
  • 4.3.1                                ...           4 months ago
  • 4.3.1-0                                ...           4 months ago
  • 4.3.0                                ...           4 months ago
  • 4.2.1                                ...           5 months ago
  • 5.0.0-5.canary-sheet                                ...           4 months ago
  • 5.0.0-4.canary-sheet                                ...           5 months ago
  • 5.0.0-3.canary-sheet                                ...           5 months ago
  • 5.0.0-1.canary-sheet                                ...           5 months ago
  • 5.0.0-0.canary-sheet                                ...           5 months ago
  • 4.2.0                                ...           7 months ago
  • 4.1.4-alpha.6                                ...           7 months ago
  • 4.1.4-alpha.5                                ...           9 months ago
  • 4.1.4-alpha.4                                ...           9 months ago
  • 4.1.4-alpha.3                                ...           9 months ago
  • 4.1.4-alpha.2                                ...           9 months ago
  • 4.1.3                                ...           10 months ago
  • 3.5.0-0                                ...           10 months ago
  • 4.1.2                                ...           a year ago
  • 4.1.1                                ...           a year ago
  • 4.1.0                                ...           a year ago
  • 4.1.0-rehydrate                                ...           a year ago
  • 4.0.3                                ...           a year ago
  • 4.0.3-0                                ...           a year ago
  • 4.0.2                                ...           a year ago
  • 4.0.1                                ...           a year ago
  • 4.0.1-0                                ...           a year ago
  • 4.0.0                                ...           a year ago
  • 4.0.0-beta.11.3                                ...           a year ago
  • 3.4.10                                ...           a year ago
  • 4.0.0-beta.11.2                                ...           a year ago
  • 4.0.0-beta.11.1-hmr2                                ...           a year ago
  • 4.0.0-beta.11.1-hmr                                ...           a year ago
  • 4.0.0-beta.11.1                                ...           a year ago
  • 4.0.0-beta.11                                ...           a year ago
  • 4.0.0-beta.9-macro2                                ...           a year ago
  • 4.0.0-beta.9-macro                                ...           a year ago
  • 4.0.0-beta.10-5                                ...           a year ago
  • 4.0.0-beta.10-4                                ...           a year ago
  • 4.0.0-beta.10-3                                ...           a year ago
  • 4.0.0-beta.10-2                                ...           a year ago
  • 4.0.0-beta.10-1                                ...           a year ago
  • 4.0.0-beta.10                                ...           a year ago
  • 4.0.0-beta.9                                ...           a year ago
  • 4.0.0-beta.8-unpure                                ...           a year ago
  • 4.0.0-beta.8                                ...           a year ago
  • 4.0.0-beta.7-hoist                                ...           a year ago
  • 3.4.9                                ...           a year ago
  • 4.0.0-beta.7                                ...           a year ago
  • 3.4.8                                ...           a year ago
  • 3.4.7                                ...           a year ago
  • 4.0.0-beta.6                                ...           a year ago
  • 4.0.0-beta.5                                ...           a year ago
  • 4.0.0-beta.4-hmr                                ...           a year ago
  • 4.0.0-beta.4                                ...           a year ago
  • 4.0.0-beta.3-purecomponent                                ...           a year ago
  • 4.0.0-beta.3-side-effect-test                                ...           a year ago
  • 4.0.0-beta.3                                ...           a year ago
  • 3.4.6                                ...           a year ago
  • 4.0.0-beta.2-0                                ...           a year ago
  • 4.0.0-beta.2                                ...           a year ago
  • 4.0.0-beta.1-2                                ...           a year ago
  • 4.0.0-beta.1-1                                ...           a year ago
  • 4.0.0-beta.1                                ...           a year ago
  • 4.0.0-beta.0-2                                ...           a year ago
  • 4.0.0-beta.0-1                                ...           a year ago
  • 4.0.0-beta.0                                ...           a year ago
  • 3.4.5                                ...           a year ago
  • 3.4.4                                ...           a year ago
  • 3.4.3                                ...           a year ago
  • 3.4.2                                ...           a year ago
  • 3.4.1                                ...           a year ago
  • 3.4.0                                ...           a year ago
  • 3.4.0-4                                ...           a year ago
  • 3.4.0-0                                ...           a year ago
  • 3.3.3                                ...           a year ago
  • 3.3.3-3                                ...           a year ago
  • 3.3.3-2                                ...           a year ago
  • 3.3.3-1                                ...           a year ago
  • 3.3.2                                ...           a year ago
  • 3.3.1-beta.0                                ...           a year ago
  • 2.4.1                                ...           a year ago
  • 3.3.1                                ...           a year ago
  • 3.3.0                                ...           a year ago
  • 3.2.6                                ...           a year ago
  • 3.2.5                                ...           2 years ago
  • 3.2.4                                ...           2 years ago
  • 3.2.3                                ...           2 years ago
  • 3.2.3-ssrmem1                                ...           2 years ago
  • 3.2.2                                ...           2 years ago
  • 3.2.2-1                                ...           2 years ago
  • 3.2.2-0                                ...           2 years ago
  • 3.2.1                                ...           2 years ago
  • 3.2.1-2                                ...           2 years ago
  • 3.2.1-1                                ...           2 years ago
  • 3.2.1-0                                ...           2 years ago
  • 3.2.0                                ...           2 years ago
  • 3.2.0-1                                ...           2 years ago
  • 3.2.0-0                                ...           2 years ago
  • 3.2.0-stylerefactor2                                ...           2 years ago
  • 3.2.0-stylerefactor1                                ...           2 years ago
  • 3.1.6                                ...           2 years ago
  • 3.1.6-2                                ...           2 years ago
  • 3.1.6-1                                ...           2 years ago
  • 3.1.6-0                                ...           2 years ago
  • 3.1.5                                ...           2 years ago
  • 3.1.4                                ...           2 years ago
  • 3.1.3                                ...           2 years ago
  • 3.1.2                                ...           2 years ago
  • 3.1.1                                ...           2 years ago
  • 3.1.0                                ...           2 years ago
  • 3.1.0-speedy6                                ...           2 years ago
  • 3.1.0-speedy5                                ...           2 years ago
  • 3.1.0-speedy4                                ...           2 years ago
  • 3.1.0-speedy3                                ...           2 years ago
  • 3.1.0-speedy2                                ...           2 years ago
  • 3.1.0-speedy                                ...           2 years ago
  • 3.1.0-3                                ...           2 years ago
  • 3.1.0-1                                ...           2 years ago
  • 3.1.0-0                                ...           2 years ago
  • 3.0.2                                ...           2 years ago
  • 3.0.1                                ...           2 years ago
  • 2.5.0-1                                ...           2 years ago
  • 2.4.0                                ...           2 years ago
  • 2.4.0-0                                ...           2 years ago
  • 2.3.3                                ...           2 years ago
  • 2.3.3-0                                ...           2 years ago
  • 2.3.2                                ...           2 years ago
  • 2.3.1                                ...           2 years ago
  • 2.3.0                                ...           2 years ago
  • 2.2.4                                ...           2 years ago
  • 2.2.3                                ...           2 years ago
  • 2.2.2                                ...           2 years ago
  • 2.2.1                                ...           2 years ago
  • 2.2.0                                ...           2 years ago
  • 2.1.3-0                                ...           2 years ago
  • 2.1.2                                ...           2 years ago
  • 2.1.1-1                                ...           2 years ago
  • 2.1.1                                ...           2 years ago
  • 2.1.1-0                                ...           2 years ago
  • 2.1.0                                ...           2 years ago
  • 2.0.1                                ...           2 years ago
  • 2.0.0                                ...           2 years ago
  • 2.0.0-19                                ...           2 years ago
  • 2.0.0-18                                ...           2 years ago
  • 1.4.6                                ...           2 years ago
  • 2.0.0-17                                ...           2 years ago
  • 2.0.0-16                                ...           2 years ago
  • 1.4.5                                ...           3 years ago
  • 2.0.0-15                                ...           3 years ago
  • 2.0.0-14                                ...           3 years ago
  • 2.0.0-13                                ...           3 years ago
  • 2.0.0-12                                ...           3 years ago
  • 2.0.0-11                                ...           3 years ago
  • 2.0.0-10                                ...           3 years ago
  • 2.0.0-9                                ...           3 years ago
  • 2.0.0-8                                ...           3 years ago
  • 2.0.0-7                                ...           3 years ago
  • 2.0.0-6                                ...           3 years ago
  • 1.4.4                                ...           3 years ago
  • 2.0.0-5                                ...           3 years ago
  • 2.0.0-4                                ...           3 years ago
  • 2.0.0-3                                ...           3 years ago
  • 2.0.0-2                                ...           3 years ago
  • 1.4.3                                ...           3 years ago
  • 2.0.0-1                                ...           3 years ago
  • 1.4.2                                ...           3 years ago
  • 1.4.1                                ...           3 years ago
  • 1.4.0                                ...           3 years ago
  • 2.0.0-0                                ...           3 years ago
  • 1.3.1                                ...           3 years ago
  • 1.3.0                                ...           3 years ago
  • 1.2.1                                ...           3 years ago
  • 1.2.0                                ...           3 years ago
  • 1.1.3                                ...           3 years ago
  • 1.1.2                                ...           3 years ago
  • 1.1.2-0                                ...           3 years ago
  • 1.1.1                                ...           3 years ago
  • 1.1.0                                ...           3 years ago
  • 1.0.12-0                                ...           3 years ago
  • 1.0.11                                ...           3 years ago
  • 1.0.10                                ...           3 years ago
  • 1.0.9                                ...           3 years ago
  • 1.0.8                                ...           3 years ago
  • 1.0.7                                ...           3 years ago
  • 1.0.6                                ...           3 years ago
  • 1.0.5                                ...           3 years ago
  • 1.0.4                                ...           3 years ago
  • 1.0.3                                ...           3 years ago
  • 1.0.2                                ...           3 years ago
  • 1.0.0                                ...           3 years ago
  • 0.4.2                                ...           3 years ago
  • 0.4.1                                ...           3 years ago
  • 0.4.0                                ...           3 years ago
  • 0.3.4                                ...           3 years ago
  • 0.3.3                                ...           3 years ago
  • 0.3.2                                ...           3 years ago
  • 0.3.1                                ...           3 years ago
  • 0.3.0                                ...           3 years ago
  • 0.2.5                                ...           3 years ago
  • 0.2.4                                ...           3 years ago
  • 0.2.3                                ...           3 years ago
  • 0.2.2                                ...           3 years ago
  • 0.2.1                                ...           3 years ago
  • 0.2.0                                ...           3 years ago
  • 0.1.9                                ...           3 years ago
  • 0.1.8                                ...           3 years ago
  • 0.1.7                                ...           3 years ago
  • 0.1.6                                ...           3 years ago
  • 0.1.5                                ...           3 years ago
  • 0.1.4                                ...           3 years ago
  • 0.1.3                                ...           3 years ago
  • 0.1.2                                ...           3 years ago
  • 0.1.1                                ...           3 years ago
  • 0.1.0                                ...           3 years ago
  • 0.0.6                                ...           3 years ago
  • 0.0.5                                ...           3 years ago
  • 0.0.5-2                                ...           3 years ago
  • 0.0.5-1                                ...           3 years ago
  • 0.0.5-0                                ...           3 years ago
  • 0.0.4                                ...           3 years ago
  • 0.0.3                                ...           3 years ago
  • 0.0.2                                ...           3 years ago
  • 0.0.1                                ...           3 years ago
Downloads
Today 14,857
This Week 27,612
This Month 218,131
Last Day 12,755
Last Week 122,353
Last Month 384,026
Dev Dependencies (6)
Dependents (6779)