CSS is broken

Sergio Zamarro
Mar 23, 2017 · 2 min read
Image for post
Image for post

Yes, CSS is broken. Anyone who has used CSS in a big project knows it. Some of the problems are these:

  • Global scope
  • Separation of technologies
  • Implicit styles
  • Dead code

How many !important do you have in your project?

Image for post
Image for post
162 !importans in 34 files!

I did a search on my project and found 162 !important in 34 files. This project has 4 contributors and more than 1200 commits. That is ridiculous and it’s caused by global styles

Image for post
Image for post

I write components so… Why global styles? If we have local styles we will not have this problem.

I love to write components in React since you can write the template and the logic in the same file… But where can I write the styles? Yes, in an external css file, but… Why separate the styles? Why do we need to write the styles in a css file?

Styled-components solve this problem, using styled-components (https://styled-components.com/) we can write styles in Javascript and create a component with those styles.

Forget methodologies and conventions such as BEM, ITCSS, SMACSS… and let’s create styled components!

How many times you spend a long time searching a css file for a view? This is because CSS is not explicit. When you create a component with styled-component you are forced to define the component styles in the same file, this is explicit. Explicit is better than implicit.

What about the dead code? How many times have you removed some html tags from the template but didn’t remove the styles? With styled-components, you will not have this problem, because if you remove the component you remove the styles!

Image for post
Image for post

Styled-components it’s not a hype or part of Javascript fatigue, styled-components is the future!

Welcome to a place where words matter. On Medium, smart voices and original ideas take center stage - with no ads in sight. Watch
Follow all the topics you care about, and we’ll deliver the best stories for you to your homepage and inbox. Explore
Get unlimited access to the best stories on Medium — and support writers while you’re at it. Just $5/month. Upgrade

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store