1 | <div align="center">
|
2 | <a href="https://www.styled-components.com">
|
3 | <img alt="styled-components" src="https://raw.githubusercontent.com/styled-components/brand/master/styled-components.png" height="150px" />
|
4 | </a>
|
5 | </div>
|
6 |
|
7 | <br />
|
8 |
|
9 | <div align="center">
|
10 | <strong>Visual primitives for the component age. Use the best bits of ES6 and CSS to style your apps without stress 💅</strong>
|
11 | <br />
|
12 | <br />
|
13 | <a href="https://www.npmjs.com/package/styled-components"><img src="https://www.styled-components.com/proxy/downloads.svg" alt="downloads: 600k/month"></a>
|
14 | <a href="#backers" alt="sponsors on Open Collective"><img src="https://opencollective.com/styled-components/backers/badge.svg" /></a> <a href="#sponsors" alt="Sponsors on Open Collective"><img src="https://opencollective.com/styled-components/sponsors/badge.svg" /></a> <a href="https://discord.gg/hfGUrbrxaU">
|
15 | <img alt="Discord" src="https://img.shields.io/discord/818449605409767454?logo=discord" /></a>
|
16 | <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>
|
17 | <a href="#alternative-installation-methods"><img src="https://img.shields.io/badge/module%20formats-umd%2C%20cjs%2C%20esm-green.svg" alt="module formats: umd, cjs, esm"></a>
|
18 | <a href="https://codecov.io/gh/styled-components/styled-components"><img src="https://codecov.io/gh/styled-components/styled-components/coverage.svg?branch=main" alt="Code Coverage"></a>
|
19 | </div>
|
20 |
|
21 | ---
|
22 |
|
23 | **Upgrading from v5?** See the [migration guide](https://styled-components.com/docs/faqs#what-do-i-need-to-do-to-migrate-to-v6).
|
24 |
|
25 | Utilizing [tagged template literals](https://www.styled-components.com/docs/advanced#tagged-template-literals) (a recent addition to JavaScript) and the [power of CSS](https://www.styled-components.com/docs/api#supported-css), `styled-components` allow 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!
|
26 |
|
27 | ```jsx
|
28 | const Button = styled.button`
|
29 | color: grey;
|
30 | `;
|
31 | ```
|
32 |
|
33 | Alternatively, you may use [style objects](https://www.styled-components.com/docs/advanced#style-objects). This allows for easy porting of CSS from inline styles, while still supporting the more advanced styled-components capabilities like component selectors and media queries.
|
34 |
|
35 | ```jsx
|
36 | const Button = styled.button({
|
37 | color: 'grey',
|
38 | });
|
39 | ```
|
40 |
|
41 | Equivalent to:
|
42 |
|
43 | ```jsx
|
44 | const Button = styled.button`
|
45 | color: grey;
|
46 | `;
|
47 | ```
|
48 |
|
49 | `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](https://www.styled-components.com/docs/basics#react-native) for more information.
|
50 |
|
51 | _Supported by [Front End Center](https://frontend.center). Thank you for making this possible!_
|
52 |
|
53 | ---
|
54 |
|
55 | ## [Docs](https://www.styled-components.com/docs)
|
56 |
|
57 | **See the documentation at [styled-components.com/docs](https://www.styled-components.com/docs)** for more information about using `styled-components`!
|
58 |
|
59 | Quicklinks to some of the most-visited pages:
|
60 |
|
61 | - [**Getting started**](https://www.styled-components.com/docs/basics)
|
62 | - [API Reference](https://styled-components.com/docs/api)
|
63 | - [Theming](https://www.styled-components.com/docs/advanced#theming)
|
64 | - [Server-side rendering](https://www.styled-components.com/docs/advanced#server-side-rendering)
|
65 | - [Tagged Template Literals explained](https://www.styled-components.com/docs/advanced#tagged-template-literals)
|
66 |
|
67 | ---
|
68 |
|
69 | ## Example
|
70 |
|
71 | ```jsx
|
72 | import React from 'react';
|
73 |
|
74 | import styled from 'styled-components';
|
75 |
|
76 | // Create a <Title> react component that renders an <h1> which is
|
77 | // centered, palevioletred and sized at 1.5em
|
78 | const Title = styled.h1`
|
79 | font-size: 1.5em;
|
80 | text-align: center;
|
81 | color: palevioletred;
|
82 | `;
|
83 |
|
84 | // Create a <Wrapper> react component that renders a <section> with
|
85 | // some padding and a papayawhip background
|
86 | const Wrapper = styled.section`
|
87 | padding: 4em;
|
88 | background: papayawhip;
|
89 | `;
|
90 |
|
91 | function MyUI() {
|
92 | return (
|
93 | // Use them like any other React component – except they're styled!
|
94 | <Wrapper>
|
95 | <Title>Hello World, this is my first styled component!</Title>
|
96 | </Wrapper>
|
97 | );
|
98 | }
|
99 | ```
|
100 |
|
101 | This is what you'll see in your browser:
|
102 |
|
103 | <div align="center">
|
104 | <a href="https://styled-components.com">
|
105 | <img alt="Screenshot of the above code ran in a browser" src="http://i.imgur.com/wUJpcjY.jpg" />
|
106 | </a>
|
107 | </div>
|
108 |
|
109 | ---
|
110 |
|
111 | ## Looking for v5?
|
112 |
|
113 | The `main` branch is for the most-current version of styled-components, currently v6. For changes targeting v5, please point your PRs at the `legacy-v5` branch.
|
114 |
|
115 | ---
|
116 |
|
117 | ## Built with `styled-components`
|
118 |
|
119 | 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 are also a whole lot of interesting apps and sites that people have built using styled-components.
|
120 |
|
121 | Make sure to head over to [awesome-styled-components](https://github.com/styled-components/awesome-styled-components) to see them all! And please contribute and add your own work to the list so others can find it.
|
122 |
|
123 | ---
|
124 |
|
125 | ## Contributing
|
126 |
|
127 | If you want to contribute to `styled-components` please see our [contributing and community guidelines](./CONTRIBUTING.md), they'll help you get set up locally and explain the whole process.
|
128 |
|
129 | Please also note that all repositories under the `styled-components` organization follow our [Code of Conduct](./CODE_OF_CONDUCT.md), make sure to review and follow it.
|
130 |
|
131 | ---
|
132 |
|
133 | ## Badge
|
134 |
|
135 | Let everyone know you're using _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)
|
136 |
|
137 | ```md
|
138 | [![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)
|
139 | ```
|
140 |
|
141 | ---
|
142 |
|
143 | ## Contributors
|
144 |
|
145 | This project exists thanks to all the people who contribute. [[Contribute](CONTRIBUTING.md)].
|
146 | <a href="https://github.com/styled-components/styled-components/graphs/contributors"><img src="https://opencollective.com/styled-components/contributors.svg?width=890" /></a>
|
147 |
|
148 | ---
|
149 |
|
150 | ## Backers
|
151 |
|
152 | Thank you to all our backers! 🙏 [[Become a backer](https://opencollective.com/styled-components#backer)]
|
153 |
|
154 | <a href="https://opencollective.com/styled-components#backers" target="_blank"><img src="https://opencollective.com/styled-components/backers.svg?width=890"></a>
|
155 |
|
156 | ---
|
157 |
|
158 | ## Sponsors
|
159 |
|
160 | Support this project by becoming a sponsor. Your logo will show up here with a link to your website. [[Become a sponsor](https://opencollective.com/styled-components#sponsor)]
|
161 |
|
162 | <a href="https://opencollective.com/styled-components/sponsor/0/website" target="_blank"><img src="https://opencollective.com/styled-components/sponsor/0/avatar.svg"></a>
|
163 | <a href="https://opencollective.com/styled-components/sponsor/1/website" target="_blank"><img src="https://opencollective.com/styled-components/sponsor/1/avatar.svg"></a>
|
164 | <a href="https://opencollective.com/styled-components/sponsor/2/website" target="_blank"><img src="https://opencollective.com/styled-components/sponsor/2/avatar.svg"></a>
|
165 | <a href="https://opencollective.com/styled-components/sponsor/3/website" target="_blank"><img src="https://opencollective.com/styled-components/sponsor/3/avatar.svg"></a>
|
166 | <a href="https://opencollective.com/styled-components/sponsor/4/website" target="_blank"><img src="https://opencollective.com/styled-components/sponsor/4/avatar.svg"></a>
|
167 | <a href="https://opencollective.com/styled-components/sponsor/5/website" target="_blank"><img src="https://opencollective.com/styled-components/sponsor/5/avatar.svg"></a>
|
168 | <a href="https://opencollective.com/styled-components/sponsor/6/website" target="_blank"><img src="https://opencollective.com/styled-components/sponsor/6/avatar.svg"></a>
|
169 | <a href="https://opencollective.com/styled-components/sponsor/7/website" target="_blank"><img src="https://opencollective.com/styled-components/sponsor/7/avatar.svg"></a>
|
170 | <a href="https://opencollective.com/styled-components/sponsor/8/website" target="_blank"><img src="https://opencollective.com/styled-components/sponsor/8/avatar.svg"></a>
|
171 | <a href="https://opencollective.com/styled-components/sponsor/9/website" target="_blank"><img src="https://opencollective.com/styled-components/sponsor/9/avatar.svg"></a>
|
172 |
|
173 | ---
|
174 |
|
175 | ## License
|
176 |
|
177 | Licensed under the MIT License, Copyright © 2016-present Glen Maddern and Maximilian Stoiber.
|
178 |
|
179 | See [LICENSE](./LICENSE) for more information.
|
180 |
|
181 | ---
|
182 |
|
183 | ## Acknowledgements
|
184 |
|
185 | 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.
|
186 |
|
187 | Special thanks to [@okonet](https://github.com/okonet) for the fantastic logo.
|