DEV Community

Discussion on: STOP writing CSS, 10 reasons why

Collapse
 
shadowtime2000 profile image
shadowtime2000

CSS has variables though.

Collapse
 
aspiiire profile image
Aspiiire

Yes i knew that comment was coming hahha, but are not the same as SASS one

Collapse
 
sno2 profile image
Carter Snook

Sass variables are definitely not the same as CSS variables. Sass is a pre-compiled language; therefore, you never run sass in the browser. Sass compiles your code into regular css. It doesn't use CSS Variables. Here is an example sass file:

$myColor: #fff;
html
  color: $myColor
Enter fullscreen mode Exit fullscreen mode

and the compiled file:

html {
  color: #fff;
}
Enter fullscreen mode Exit fullscreen mode

As you can see, we don't have to use the CSS variables which aren't supported by all browsers.

Collapse
 
gsarig profile image
Giorgos Sarigiannidis • Edited

Actually, I believe that CSS variables are better than SASS's, for two main reasons:

  1. They can be modified from within media queries. For example, you write some css which use a specific value stored in a variable and then, on the media query, you don't need to repeat the same code if all you need is a few calculations based on a different value. You can just declare the variable again, with the new value.
  2. They can be manipulated with JavaScript, which is a big thing.

Personally, I like SASS and I use it all the time, but I've started using native variables for the aforementioned reason.

Here is a small pen that demonstrates how those two can work together and how easy it is to manipulate them with JS (and a more detailed explanation here).

Collapse
 
aspiiire profile image
Aspiiire

Thanks for sharing you knowledge Giorgos, I totally agree, I didn't know about the root thing... and thanks for the article :)

Collapse
 
shadowtime2000 profile image
shadowtime2000

Yeah, I agree they are better than SASS variables. I am also pretty sure that some CSS frameworks are using CSS variables to allow you to customize the theme colors which is a bonus when you don't want to style stuff but you want to dynamically change the theme colors.

Collapse
 
denvercoder1 profile image
Jonah Lawrence

CSS has math too

height: calc(100vh - 50px);
Enter fullscreen mode Exit fullscreen mode