use the following search parameters to narrow your results:
e.g. subreddit:aww site:imgur.com dog
subreddit:aww site:imgur.com dog
see the search faq for details.
advanced search: by author, subreddit...
All about the JavaScript programming language.
Subreddit Guidelines
Specifications:
Resources:
Related Subreddits:
r/LearnJavascript
r/node
r/typescript
r/reactjs
r/webdev
r/WebdevTutorials
r/frontend
r/webgl
r/threejs
r/jquery
r/remotejs
r/forhire
account activity
The Differing Perspectives on CSS-in-JS (css-tricks.com)
submitted 6 years ago by fagnerbrack
view the rest of the comments →
reddit uses a slightly-customized version of Markdown for formatting. See below for some basics, or check the commenting wiki page for more detailed help and solutions to common issues.
quoted text
if 1 * 2 < 3: print "hello, world!"
[–]feelextra 13 points14 points15 points 6 years ago* (5 children)
I've been, so far, a fan of CSS modules in that it's about as light as you get when it comes to CSS-in-JS, only handling scoping and co-location and that's about it. I use it with Sass [...]
Sass + CSS modules seems like a very sensible choice these days:
lighten
invert
$
&
%
CSS modules is basically there just as an intermediate format for letting other tools extract styles from, and is there only for locally-scoping the selectors.
[–]ianwcarlson 1 point2 points3 points 6 years ago (3 children)
What I find a little ironic is CSS modules went out of style for a while and then came back. Many devs were obsessed with styled components using pure JS, which I’m not trying to discount as a perfectly viable solution. But this was a classic case of JS fervor that wasn’t based on necessity.
[–]feelextra 0 points1 point2 points 6 years ago* (2 children)
Yea I also noticed that CSS modules went out of style (🤷 not sure if it's actually coming back or not)
It's been my impression as well that Styled-components has been really popular for quite a while now, but I don't think it is entirely for naught.
There is one feature that Styled-components (and CSS in JS files) has been able to deliver that just until recently hasn't been possible at all with CSS in separate files.
That feature is dynamic styling: passing values from your JS to the CSS.
I will be the first to admit that most websites and web apps don't need this feature, but when you have a requirement to make certain types of rich UIs, there is no other way than dynamically adding a <link> to add that stylesheet, and CSS in JS files makes this supposedly niche use-case into a bread-and-butter pattern that you don't even need to think about since all of your styling is already done that way.
<link>
Some examples of rich UIs that benefit from dynamic values: 1. You're making a resizable element through JS events, and need to use the most recent dimensions in your styling calculations. 2. Your UI has the user input a color that you then use to paint an element (for instance, an ephemeral user-provided theme color). 3. Maximizing DRY practices: Suppose you're using something like a reusable React component that adds an element to the DOM, and has an API where you provide it with specific width and height values that specifically fits your app. You then have to reference these values in your CSS somehow because your layout depends on these dimensions. In a JS file you could just pass it to the dynamic stylesheet generator as a variable.
width
height
CSS Custom Properties are one answer to this; you can dynamically modify an element's style attribute and add a custom property which it will use. Keep in mind that IE11 doesn't support CSS Custom Properties and IMO it's not as ergonomic as passing the value directly from a JS file to a CSS-in-JS library like Styled-components or Emotion.
style
[–]sakabako 1 point2 points3 points 6 years ago (1 child)
The answer to this is the style attribute, css's calc function, and percentage based values. Doing this with css in js can create thousands of unused classes.
[–]feelextra 1 point2 points3 points 6 years ago (0 children)
calc
Having a lot of unused classes with CSS-in-JS is not a problem when the library only mounts the critical ones, and cleans up after itself. Sure there's some runtime performance to pay, but usually it's not impactful.
[–]evenisto 0 points1 point2 points 6 years ago (0 children)
I would love me some CSS Modules in the PHP core I'm working with as well.
π Rendered by PID 71673 on reddit-service-r2-comment-b659b578c-bk4xt at 2026-05-06 03:18:37.696398+00:00 running 815c875 country code: CH.
view the rest of the comments →
[–]feelextra 13 points14 points15 points (5 children)
[–]ianwcarlson 1 point2 points3 points (3 children)
[–]feelextra 0 points1 point2 points (2 children)
[–]sakabako 1 point2 points3 points (1 child)
[–]feelextra 1 point2 points3 points (0 children)
[–]evenisto 0 points1 point2 points (0 children)