DEV Community

Cover image for Styled Components vs. CSS Stylesheets

Styled Components vs. CSS Stylesheets

Nick Parsons on January 20, 2020

Over the last few years, CSS-in-JS solutions have become prevalent across the front-end landscape with many offerings such as styled-components, an...
Collapse
 
dance2die profile image
Sung M. Kim

Thanks for the article, Nick.

Would you consider embedding gist?

{% gist https://gist.github.com/LukeSmetham/fa938f04d2dd834643b49cdc6d490dcc %} show the gist.

Collapse
 
nickparsons profile image
Nick Parsons

Thanks for the pro-tip! Done and done!

Collapse
 
dance2die profile image
Sung M. Kim

Thanks. It looks awesome :)

Collapse
 
theodesp profile image
Theofanis Despoudis

Styled components are nice but they need more adoption to become mainstream. For example let's say I want to buy an HTML template (because I'm bored to build my own theme from scratch). Almost all the times they are using some sort of preprocessors like SCSS or Less.

Collapse
 
lukesmetham profile image
Luke Smetham • Edited

I wouldn't say that it isn't mainstream at all, it's a huge library - but I totally agree, it can be harder to implement styled-components as effectively in parallel with things like SCSS and Less which can make it harder to adopt - although you being bored enough to buy a template that doesn't work perfectly with your stack shouldn't be a good pointer of how successful a library is either 😝

Collapse
 
johnkazer profile image
John Kazer • Edited

You made a clear point for me - engineers will like components, designers probably not (speaking as the former - so I am speculating about the latter!). Too much confusion of professional roles in styled components?

Collapse
 
lukesmetham profile image
Luke Smetham

I 100% disagree. Fair enough it may be overkill if your writing a very small app, but even just to have legitimate media queries and SCSS rules like & > * + * is a huge win over doing plain style in your jsx file surely.

Collapse
 
sm0ke profile image
Sm0ke

Nice, Thanks for sharing!

Collapse
 
nickparsons profile image
Nick Parsons

Thank you! Of course!

Collapse
 
luisnomad profile image
Luis Serrano 🇪🇺 • Edited

I really despise CSS-in-JS. I think it's a personal taste, though. I also see your long list of styled-components CONS list, with huge and loud arguments that totally outweigh the PROS... and yet you recommend going with it. So that really confirms is a matter of taste.

Collapse
 
ctrlsquid profile image
zach

Most of my applications that I build with a frontend are SPA at this point. Even when they're not, having the styled-components more closely associated with my JS is really nice.
I definitely think there's a use case for both, but I find myself favoring styled-components more and more often.

Collapse
 
lukesmetham profile image
Luke Smetham

import this in a separate file and make it the default export, move all the CSS from your template inside of the template string and then import the file into your global styles.

Then you can still utilize your theme and all the other SC features inside of the CSS provided by your template and customize it however you see fit.

Collapse
 
madza profile image
Madza

styled components were designed by focusing on full-stack devs :)