How to use global variables in CSS-Modules?

user818700 picture user818700 · Nov 24, 2016 · Viewed 23k times · Source

I'm busy learning React with CSS-Modules and I don't quite understand how one would store variables? For example, in Sass you're able to do this:

// _variables.scss
$primary-color: #f1f1f1; 

// heading.scss
@import './variables';
.heading {
  color: $primary-color
}

How do you achieve this in CSS Modules?

Answer

Mantas picture Mantas · Apr 21, 2019

Check this out

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


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

.component{
  color: var(--color-black);
}