DEV Community


Discussion on: Don't Trust the Cascade - Why I write CSS in JavaScript

moopet profile image
Ben Sinclair

I guess I see people on Twitter demoing things using javascript objects to represent the style for (say) a button inside a widget. It's not usually doing anything more than you would using normal CSS, and I think it has a lot of drawbacks:

There are usually no consistent hooks so regular stylesheets will have a very difficult time affecting the way something looks. Why is that a problem? It's a problem for accessibility - if I want to add a custom stylesheet or use userstyles or anything, suddenly it's a whole lot harder if not impossible.

If I want to re-skin my site for a temporary christmas takeover, I'm out of luck, unless I import all the base styles and colours from a separate source, like a common javascript module or other kind of data store.

If you want to use the same component in multiple places, like in a sidebar, on a tablet, in a header, on someone's desktop with customised colour profiles, in print or as part of an app... you're either going to have to make new components or you're going to have to recreate media queries or the cascade, in javascript. I don't know why anyone would do that, but feel free to ELI5!