CSS in JS is a way of writing css styles in javascript with much more flexiblity and features.
I have already created a video about on Cules Coding youtube channel.
Suppose you have a large scale application with a lot of components.
Each components has different styles. So you add class names to them. Those class names have some styling.
Now it is easy to mess up with component names like the picture below.
And your whole layout breaks like this. // gif
The solution is Scoping CSS
. Instead of writing css globaly in css styles, what if we can write them inside
the component. Then the css styles won't affect other components.
This is where css-in-js comes into play. Css in js is writing css inside javascript. And we want to write css inside javascript. Now, what css-in-js libary will do is, it will generate a unique class name to the component. And that class will have all the styles.
It will add a unique hash to the class name. Just because the hash will be unique, that's why all the component will have different style. Now we have Scoping CSS.
There are bunch of libraries out there. Popular ones are:
I like the Styled Component most. You can use whatever you want.
There are a lot of features that those libraries provides us. Like theming, props adaption, extending style and so on.
And also remember you are writing in JavaScript. That means you can create your functionalities and features. So, don't let yourself restrict witin libary features.
To learn more watch the Video.
That's it for today. If you have any question, please contact me on social media as @thatanjan. I would love to hear from you. I daily post content there. So stay safe and good bye.
My name is Anjan. I am a full stack web developer from Dhaka, Bangladesh.
I can create complex full stack web applications like social media application, blogging, e-commerce website and many more.
I love to solve problems and develop new ideas. I also enjoy sharing my knowledge to other people who are wiling to learn. That's why I write blog posts and run a youtube channel called Cules Coding
Email: anjancules@gmail.com
linkedin: @thatanjan
portofolio: anjan
Github: @thatanjan
Instagram (personal): @thatanjan
Instagram (youtube channel): @thatanjan
twitter: @thatanjan
Cules Coding will teach you full stack development. I will teach you not only the basic concepts but also the advanced concepts that other youtube channels don't cover. I will also teach you Data Structures and Algorithms with abstraction and without Math. You will also find many tutorials about developer tools and technologies. I also explain advanced concepts and technologies with simplicity.
Subscribe to Cules Coding so that my friend you don't miss any of these cool stuffs.