Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

CSS Variables vs CSS Modules @value

I was wondering what exactly is the difference between the css function var(--red) and @value red from css modules.

CSS Modules Example:

@value red from "./color.m.css";

.background {
    background-color: red;
}

CSS Var() Example:

@import "./color.m.css";

.background {
    background-color: var(--red);
}

Is there an advantage using one of them?
Thanks in advance for helping me out!

like image 571
Irazzer Avatar asked Mar 02 '26 07:03

Irazzer


1 Answers

CSS modules @value is

  1. Similar to preprocessor(sass/less) variable. Its alive in compile time.
  2. As it compiles to plain css. It works in every browser.

CSS Var() is

  1. A live variable in css file. Any change to its value is reflected live in the elements its being used.
  2. As its a new css feature, Works in modern browsers only
like image 92
Moorthy G Avatar answered Mar 03 '26 21:03

Moorthy G



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!