styled-components/styled-components


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

https://styled-components.com

License: MIT

Language: JavaScript

Keywords: css, css-in-js, react, 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


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!

v5

styled-components v5 is now officially in beta! Try it out in your project today:

npm install styled-components@beta

Notes:

  • Make sure you're on a hooks-compatible version of react (>= 16.8 for react, react-dom, and react-is)
  • If you use jest-styled-components, upgrade to the beta of that as well! npm install jest-styled-components@beta

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:

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.

Project Statistics

Sourcerank 21
Repository Size 8.62 MB
Stars 24,405
Forks 1,437
Watchers 384
Open issues 74
Dependencies 4,276
Contributors 252
Tags 175
Created
Last updated
Last pushed

Top Contributors See all

Max Stoiber Evan Jacobs Phil Plückthun Glen Maddern Patrick Arminio Konstantin Pschera Rolf Erik Lekang Viktor Havrylin Igor Oleinikov Sergey Evan Scott Bhargav Ponnapalli Chris Haz Flavio Corpa Mario Nebl Mathieu Dutour Jacob Parker Mateusz Burzyński Michal Kvasničák

Packages Referencing this Repo

styled-components-aretecode
Visual primitives for the component age. Use the best bits of ES6 and CSS to style your apps with...
Latest release 4.2.0 - Updated - 24.4K stars
sc-memoized
Visual primitives for the component age. Use the best bits of ES6 and CSS to style your apps with...
Latest release 4.2.0 - Published - 24.4K stars
mm-styled-components
Visual primitives for the component age. Use the best bits of ES6 and CSS to style your apps with...
Latest release v4.3.2 - Published - 24.4K stars
@asvetliakov/styled-components
Visual primitives for the component age. Use the best bits of ES6 and CSS to style your apps with...
Latest release 4.1.1 - Published - 24.4K stars
rax-styled-components
Visual primitives for the component age. Use the best bits of ES6 and CSS to style your apps with...
Latest release 3.4.5 - Updated - 24.4K stars
@dynasty/styled-components
Visual primitives for the component age. Use the best bits of ES6 and CSS to style your apps with...
Latest release 3.2.1 - Published - 24.4K stars
@marionebl/styled-components
Visual primitives for the component age. Use the best bits of ES6 and CSS to style your apps with...
Latest release 3.1.9 - Updated - 24.4K stars
styled-components-with-middlewares
Visual primitives for the component age. Use the best bits of ES6 and CSS to style your apps with...
Latest release 2.2.5 - Published - 24.4K stars
react-styled-skeleton
React-Skeleton - Skeleton CSS in React components
Latest release 1.0.8 - Updated - 24.4K stars
@stream-io/styled-components
Visual primitives for the component age. Use the best bits of ES6 and CSS to style your apps with...
Latest release 4.2.1 - Published - 24.4K stars
@chibikookie/styled-components
Visual primitives for the component age. Use the best bits of ES6 and CSS to style your apps with...
Latest release 4.0.0-alpha.0 - Published - 24.4K stars
styled-components-matmalkowski
Visual primitives for the component age. Use the best bits of ES6 and CSS to style your apps with...
Latest release 4.1.4-alpha.5 - Published - 24.4K stars
org.webjars.npm:styled-components
WebJar for styled-components
Latest release 4.1.4-alpha.5 - Updated - 24.4K stars
@migueloller/styled-components
Visual primitives for the component age. Use the best bits of ES6 and CSS to style your apps with...
Latest release 3.2.6 - Published - 24.4K stars
iphong-styled-components
Visual primitives for the component age. Use the best bits of ES6 and CSS to style your apps with...
Latest release 2.2.1 - Published - 24.4K stars
styled-components
Visual primitives for the component age. Use the best bits of ES6 and CSS to style your apps with...
Latest release 5.0.0-beta.3 - Updated - 24.4K stars
diakonos-styled-components
Visual primitives for the component age. Use the best bits of ES6 and CSS to style your apps with...
Latest release 3.2.3 - Published - 24.4K stars
@clentfort/styled-components
Visual primitives for the component age. Use the best bits of ES6 and CSS to style your apps with...
Latest release 4.1.4-alpha.6 - Published - 24.4K stars
styled-components-web
Visual primitives for the component age. Use the best bits of ES6 and CSS to style your apps with...
Latest release 1.0.0 - Published - 24.4K stars
@carlossless/styled-components
Visual primitives for the component age. Use the best bits of ES6 and CSS to style your apps with...
Latest release 1.1.2 - Published - 24.4K stars

Recent Tags See all

v4.3.2 June 20, 2019
v5.0.0-beta.3 June 18, 2019
v5.0.0-beta.2 June 16, 2019
v5.0.0-beta.1 June 16, 2019
v5.0.0-alpha.2 June 11, 2019
v4.3.1 June 06, 2019
v4.3.0 June 05, 2019
v4.2.1 May 30, 2019
styled-components@4.2.0 March 23, 2019
sandbox@4.2.0 March 23, 2019
v4.2.0 March 23, 2019
v4.1.3 March 21, 2019
v4.1.3 March 21, 2019
v4.1.3 March 21, 2019
styled-components@4.1.4-alpha.5 January 18, 2019

Interesting Forks See all

infernojs/styled-components
Visual primitives for the component age 💅
JavaScript - Last pushed - 3 stars - 1 forks
mehmetkursunlu/styled-components
Visual primitives for the component age. Use the best bits of ES6 and CSS to style your apps with...
JavaScript - MIT - Updated - 1 stars
Acidburn0zzz/styled-components
Visual primitives for the component age. Use the best bits of ES6 and CSS to style your apps with...
JavaScript - MIT - Updated - 1 stars
rnmp/styled-components
Visual primitives for the component age. Use the best bits of ES6 and CSS to style your apps with...
JavaScript - Updated - 1 stars
shripadk/styled-components
Visual primitives for the component age 💅
JavaScript - Last pushed - 1 stars

Something wrong with this page? Make a suggestion

Last synced: 2019-06-20 04:58:28 UTC

Login to resync this repository