DEV Community

Discussion on: CSS in JS - have we done something wrong?

Collapse
 
danspratling profile image
Dan Spratling

Personally, i think CSS-in-JS is fine but you've got to be a lot more careful when writing it. Inline styling is very easy to use but too much of it makes the code very hard to read.

The biggest benefit i've seen from CSS-in-JS is very easy bundling so that when a page loads, you're loading as little as possible.

You can also do some mathematical equations/variable manipulation which is just impossible any other way. (with a template engine you might be able to do stuff inline, but it's horrible to do).

It's up to the developer to write it correctly and it's very easy to get wrong which makes it harder to read and code around. The benefits are great but it's by no means the only way to write css.

Another great alternative is using a Utility Class library - something like Tailwind, which almost entirely removes the need for writing your own css (but that is a very different approach).

Or you could just use classic css or scss and write a really well defined webpack file to handle bundling. The great thing is, we have loads of options now.