C
C
colorkid2021-08-11 15:09:11
css
colorkid, 2021-08-11 15:09:11

What is the difference between css modules and styled-components?

What is the difference between css modules and styled-components? Both encapsulate styles inside components, well, a little differently, but what is the fundamental difference between these approaches?

Answer the question

In order to leave comments, you need to log in

3 answer(s)
T
TheSnegok, 2021-08-11
@TheSnegok

css module work only for the elements of the component into which they are imported, and styled-components for the entire component tree.
It's short, read more here :

E
Egor Zhivagin, 2021-08-11
@Krasnodar_etc

About styled-components based on what I read about this approach, no experience with it.
The root difference is that styled components are css-in-js, styles are written as a template string, inserted into the style attribute/tag. It’s already more difficult to associate preprocessors with this (probably there is no need for this)
css-modules is easier, you can use preprocessors, assemble them into bundles, chunks, or at least in the same style tag
If it’s very short) Read about css-in-js, that’s all should already be written

P
profesor08, 2021-08-11
@profesor08

styled-components if you want everything to be compact, neatly scattered around the project, and in general if you don’t want to take a steam bath.
css modules if you want to write styles in separate files, and then run around combining them to switch styles for different states.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question