CSS is broken
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?
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
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?
const Alert = styled.div`
background-color: rgba(255, 130, 110, 0.77);
box-shadow: rgba(0, 0, 0, 0.117647) 0px 1px 6px, rgba(0, 0, 0, 0.117647) 0px 1px 4px;
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!