This is how you do it with vanilla CSS Modules

// vars.css
:root {
  --color-black: #222;
}


// myComponent.module.css
@import './vars.css';

.component {
  color: var(--color-black);
}
Answer from Mantas on Stack Overflow
🌐
Medium
medium.com › @toshvelaga › using-global-css-variables-in-react-js-216f03fcdc56
Using Global CSS variables in React JS | by Tosh Velaga | Medium
March 7, 2022 - Here’s how we do it. In our src directory we create a file called variables.css. Look at the screenshot below to see our folder structure and what we keep in the variables.css file. ... We then import the variables.css file into App.js so that all the components in our app have access to it.
Discussions

Where to store global css variables?
I use SASS with CSSModules. Then i keep global variables in different files I import in respective component. Oh, I see that you don’t want to do this. But I don’t think you can. Unless whichever SASS interpreter had a way to import a file together with every other file, which imho sounds incredibly wasteful. More on reddit.com
🌐 r/reactjs
10
11
June 17, 2018
reactjs - Using global SASS variables in React component - Stack Overflow
Each import of SCSS file in JS file is treated as an isolated SASS env, therefore, there is no such thing "global variables" while using SCSS in React. This behavior requires us to import... More on stackoverflow.com
🌐 stackoverflow.com
reactjs - How to define css variables in style attribute in React and TypeScript - Stack Overflow
I want to define jsx like this: and I use --length in CSS, I a... More on stackoverflow.com
🌐 stackoverflow.com
change css root variable from react state
Or https://css-tricks.com/updating-a-css-variable-with-javascript/ More on reddit.com
🌐 r/reactjs
4
4
November 25, 2021
🌐
Josh W. Comeau
joshwcomeau.com › css › css-variables-for-react-devs
How to use CSS variables with React • Josh W. Comeau
April 13, 2020 - But I think the best way to solve this problem is with CSS variables. Instead of imperatively specifying how each component should respond at different breakpoints, what if we passed it a reactive variable that tracked that for us? ... const GlobalStyles = createGlobalStyle` html { --min-tap-target-height: 32px; @media (pointer: coarse) { --min-tap-target-height: 48px; } } `;
🌐
Epic React
epicreact.dev › css-variables
Use CSS Variables instead of React Context | Epic React by Kent C. Dodds
July 9, 2024 - With CSS Variables, you can get the values in your CSS with var(--css-variable-name) and in your JavaScript using getComputedStyle(element).getPropertyValue('--css-variable-name') (which you really don't need to do...)
🌐
DEV Community
dev.to › diballesteros › how-to-use-global-mixins-and-variables-with-css-modules-in-react-with-sass-37ie
How to use global mixins and variables with CSS Modules in React with SASS - DEV Community
March 21, 2022 - Starting an app with Create-React-App or next a fairly common option is to use CSS Modules which guarantees that the styles per component will not have any conflicts, however, it does mean it’s slightly different to access these global variables.
🌐
Reddit
reddit.com › r/reactjs › where to store global css variables?
r/reactjs on Reddit: Where to store global css variables?
June 17, 2018 -

Hey,

I set up my react project to support sass following this article, which worked out fine (I configured the webpack part slightly different though).

Since I will use a set of different colors throughout my application, I would like to store these into variables, which I can access from my components for example. Since I don't want to import my global.scss file everytime into every components .scss, I would like to somehow set the variables global, making them accessible without imports.

How could I achieve this?

🌐
LogRocket
blog.logrocket.com › home › using css variables in react native
Using CSS variables in React Native - LogRocket Blog
June 4, 2024 - If you take a hard look at the CSS variable declarations and their usage in the CSS section above, you might wonder what the big deal was about. You could pretty much have set those style values for the paragraph element directly, rather than doing it this way. So what’s the big win here? The benefit of doing it this way is that the same root styles can now be applied to any other elements, as well as React Native components. We’ll explore this in the next section. We’ll make a few global style variables that can be reused for both p and Text.
Find elsewhere
🌐
Atomizedobjects
atomizedobjects.com › blog › react › how-to-use-css-variables-with-react
How to use css variables with React | Atomized Objects
You can define css variables by ... scope can exist. For example, if you define a variable on the body tag then the variable will be accessible to all child and sub child elements of the body so essentially making the variable global....
🌐
React Suite
rsuitejs.com › guide › css-variables
CSS Variables - React Suite
All modern browsers support CSS variables. In React Suite, we use CSS variables to define the styles of components, and you can customize the styles of components by overriding CSS variables.
🌐
DEV Community
dev.to › prashantbhat84 › css-variables-in-react-js-259c
CSS Variables in React.js - DEV Community
April 29, 2021 - This is a standard react application structure. We have the index.css file where we can define the root pseudo selector. In that we can define the CSS variables which we can use throughout the application.
🌐
YouTube
youtube.com › shorts › vRLNLot9hII
How to Declare & Use Global Variable in CSS || React #react #css - YouTube
In this video, I explain how to use and declare global variables in CSS for ReactJS.#css #react #global #variable
Published   August 13, 2023
🌐
Patrick Desjardins
patrickdesjardins.com › blog › react-css-variable-component-css-files
Patrick Desjardins Blog - How to use CSS variables in React components and CSS files
If you want to define at a single ... your React components and inside CSS files, you need a central location. I enjoy keeping colors and styles all in CSS files (or CSS modules). Settling into a solution of defining all values in CSS as the source of truth is technically possible. The first step is to define your variables. For example, you can specify a background color at the :root. Of course, it could be at another level, but I prefer setting global variables ...
🌐
Nikita Hlopov
nikitahl.com › handling-css-variables-with-react
Handling CSS variables (Custom Properties) in React
September 17, 2019 - Then let’s create a cssProperties object inside render method and assign this object to a style attribute. This way CSS variables and other CSS properties will be assigned to a .container element if exists.
🌐
Medium
medium.com › geckoboard-under-the-hood › how-we-made-our-product-more-personalized-with-css-variables-and-react-b29298fde608
How we made our product more personalized with CSS Variables and React | by Dan Bahrami | Geckoboard: Under The Hood | Medium
April 5, 2018 - I already have!It’s called react-custom-properties and it is slightly more powerful than the example above. It can apply CSS Variables globally or to a specific part of your UI, it can also be nested so you can go crazy with CSS Variables!
🌐
DEV Community
dev.to › ninjasoards › make-a-custom-night-mode-toggle-w-react-css-variables-272o
Make a custom night mode toggle w/React & CSS Variables - DEV Community
July 30, 2021 - The CSS variable can then be assigned to any element and the colors will change upon clicking the toggle switch. The variables can be assigned globally...
🌐
Bitstack
blog.bitsrc.io › theming-react-components-with-css-variables-ee52d1bb3d90
Theming React Components with CSS Variables | by Eden Ella | Bits and Pieces
May 22, 2023 - That could be either theming through higher-order components, passing themes as props (usually with the help of React.Context) or using popular libraries like styled-components. Today, thanks to ‘CSS custom properties’, a.k.a ‘CSS variables’, we shift the weight towards plain CSS.
🌐
Webscale
section.io › home › blog
Dynamically Update React and JavaScript with CSS ...
June 24, 2025 - Get the latest insights on AI, personalization, infrastructure, and digital commerce from the Webscale team and partners.
🌐
Medium
medium.com › @diballesteros › how-to-use-global-mixins-and-variables-with-css-modules-in-react-with-sass-cfb064176f55
How to use global mixins and variables with CSS Modules in React with SASS | by Diego Ballesteros (Relatable Code) | Medium
November 7, 2021 - Create-react-app docs recommend using node-sass for the styling, however, this is deprecated so I would suggest using sass (Dart Sass) as it is still actively receiving support. This can be quickly done with: ... For variables it would be something very similar, let’s have a file with the name _variables.scss: ... This can be quite useful to reuse a lot of variables and similar styles throughout the entire project while still maintaining the module structure.