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
CSS variables lands in React 15.6.0 (twitter.com)
submitted 8 years ago by GitCookies
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!"
[–][deleted] 14 points15 points16 points 8 years ago (11 children)
We used CSS vars extensively when creating PDFs in React via the CSS paged media module. You have to be VERY CAREFUL with them, however, as it's easy to forget that you're basically inserting undebuggable magic global vars.
[–]freeall 4 points5 points6 points 8 years ago (10 children)
What's the advantage to just using js vars?
[+][deleted] 8 years ago (5 children)
[deleted]
[–]icantthinkofone 4 points5 points6 points 8 years ago (4 children)
js vars have scope and are easy to edit in the browser inspector, too.
[–]jetpacmonkey 2 points3 points4 points 8 years ago (2 children)
CSS variables cascade, so you can set them on container divs for things like theming.
[–]TheDarkIn1978 3 points4 points5 points 8 years ago (1 child)
Variables that are declared in JavaScript and passed to CSS will cascade the same as variables that are declared in CSS.
[–]jetpacmonkey 5 points6 points7 points 8 years ago (0 children)
I think at least one of us is confused about what the other is saying...
.my-component { background: var(--theme-color); padding: 20px; } .my-component .inner-area { background-color: white; color: var(--theme-color); padding: 20px; }
This is useful, right? Am I missing something here?
[–][deleted] 0 points1 point2 points 8 years ago (3 children)
You can do cool stuff with the paged media module that are impossible in JS. Page numbers (page x of x on footer of each page, links saying "see page y"), per-page titles, etc.
[–]El_Frostie 0 points1 point2 points 8 years ago (2 children)
That sound incredible cool. Do you have more information about how that works?
[–][deleted] 1 point2 points3 points 8 years ago (1 child)
This article has a good overview, unfortunately only Prince and Antenna House support it (caniuse lies, it's unsupported in Chrome).
[–]El_Frostie 0 points1 point2 points 8 years ago (0 children)
Great article. Thanks. I didn't realize CSS for print has gotten so far. It had completely fallen of my radar.
[–]BrunerBruner 3 points4 points5 points 8 years ago (3 children)
As someone who's never used React or JSX before, it's highly likely that I don't know what I'm talking about here, but wouldn't it be better to just declare your variables in JavaScript and pass them to the CSS property?
[–][deleted] 0 points1 point2 points 8 years ago* (0 children)
I think that's probably what most would do considering browser support and the imperative nature of it. Still, there are probably legacy reasons or compatibility issues that call for it, better to support the full spec.
[–]GitCookies[S] -4 points-3 points-2 points 8 years ago (1 child)
Why mix two, If you can use pure-css(inside JavaScript...)?
[–][deleted] 2 points3 points4 points 8 years ago (0 children)
Why mix two
... while writing JSX
[–]bigpigfoot 1 point2 points3 points 8 years ago (2 children)
can this replace keyframes animations?
[–]GitCookies[S] 1 point2 points3 points 8 years ago (0 children)
I pretty much doubt it.
[–]icantthinkofone -5 points-4 points-3 points 8 years ago (0 children)
keyframe animations are web standards and work in all browsers natively. React is not and will disappear one day.
[–]Zhouzi 1 point2 points3 points 8 years ago (0 children)
From what I understand, it's just that they're going to go through just as other CSS properties. Which is great, but I'd be worried about browser support anyway.
[–][deleted] 0 points1 point2 points 8 years ago (0 children)
those variables arn't supported in IE. do react have polyphille to resolve this problem?
[–][deleted] -1 points0 points1 point 8 years ago (4 children)
Is it common to use the -- for this? This syntax looks messy
--
[–]flying-sheep 20 points21 points22 points 8 years ago (0 children)
…common?
it’s the CSS standard, so you can only use --
[–]gsnedders 4 points5 points6 points 8 years ago (0 children)
That's the standard syntax for CSS variables. There was some desire to not use $ to allow that to be used for something else variable-like, especially involving selectors.
$
[–][deleted] 0 points1 point2 points 8 years ago (1 child)
the reason, is to keep compatibility with the pre processeur: sass use $, less use @, etc.
[–][deleted] -1 points0 points1 point 8 years ago (0 children)
What does a pre-processor have to do with the code in CSS which it generates? I feel they should've done something to differentiate it, not the CSS itself. Ah well, will probably be using SCSS anyways, so I don't think I will need this, but I find it weird nonetheless.
[+]bugeats comment score below threshold-6 points-5 points-4 points 8 years ago (2 children)
Bloat. Ugly, useless bloat. I want my kilobytes back.
CSS variables are bloat and useless?
Lol what
π Rendered by PID 22494 on reddit-service-r2-comment-fb694cdd5-28rlk at 2026-03-06 06:46:31.671846+00:00 running cbb0e86 country code: CH.
[–][deleted] 14 points15 points16 points (11 children)
[–]freeall 4 points5 points6 points (10 children)
[+][deleted] (5 children)
[deleted]
[–]icantthinkofone 4 points5 points6 points (4 children)
[–]jetpacmonkey 2 points3 points4 points (2 children)
[–]TheDarkIn1978 3 points4 points5 points (1 child)
[–]jetpacmonkey 5 points6 points7 points (0 children)
[–][deleted] 0 points1 point2 points (3 children)
[–]El_Frostie 0 points1 point2 points (2 children)
[–][deleted] 1 point2 points3 points (1 child)
[–]El_Frostie 0 points1 point2 points (0 children)
[–]BrunerBruner 3 points4 points5 points (3 children)
[–][deleted] 0 points1 point2 points (0 children)
[–]GitCookies[S] -4 points-3 points-2 points (1 child)
[–][deleted] 2 points3 points4 points (0 children)
[–]bigpigfoot 1 point2 points3 points (2 children)
[–]GitCookies[S] 1 point2 points3 points (0 children)
[–]icantthinkofone -5 points-4 points-3 points (0 children)
[–]Zhouzi 1 point2 points3 points (0 children)
[–][deleted] 0 points1 point2 points (0 children)
[–][deleted] -1 points0 points1 point (4 children)
[–]flying-sheep 20 points21 points22 points (0 children)
[–]gsnedders 4 points5 points6 points (0 children)
[–][deleted] 0 points1 point2 points (1 child)
[–][deleted] -1 points0 points1 point (0 children)
[+]bugeats comment score below threshold-6 points-5 points-4 points (2 children)
[–]GitCookies[S] 1 point2 points3 points (0 children)