Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Can't use CSS Variables inside of filter grayscale with SCSS

I'm trying to make the 100% in filter: grayscale(100%); be a CSS variable so I can dynamically change it later with JavaScript.

--percent: 100%;
filter: grayscale(var(--percent));

This is not compiling with Dart sass. It's telling me:

Dart Sass failed with this error: $color: var(--percent) is not a color. filter: grayscale(var(--percent));

Which doesn't make any sense to me as it works just fine with normal CSS.

How can I get this normal CSS Variable to work with Dart Sass?

like image 914
briann Avatar asked Oct 31 '25 13:10

briann


1 Answers

Because it conflicts with the grayscale function of Sass and Sass-specific functions can't handle CSS variables.

Use it this way:

--percent: 100%;
filter: #{"grayscale(var(--percent))"};
like image 131
doğukan Avatar answered Nov 03 '25 04:11

doğukan