Cannot use CSS variables (var(--bs-primaryColor)) as $primary in Bootstrap SCSS – throws “is not a color” error #41746
Unanswered
harshsavadia
asked this question in
Q&A
Replies: 1 comment 1 reply
-
SCSS cannot use var(--bs-*) in functions like mix() or darken() because CSS variables exist only at runtime, while SCSS variables are compile-time. Recommended approach:
This way, Bootstrap utilities work at compile-time, and you can change theme colors at runtime without recompiling. You cannot pass CSS variables directly to SCSS functions. |
Beta Was this translation helpful? Give feedback.
1 reply
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
-
We are trying to use dynamic colors coming from our backend to replace Bootstrap’s primary and secondary colors at runtime. Our approach is to map Bootstrap’s $primary and $secondary SCSS variables to CSS custom properties so we can update them in the browser:
However, when compiling, Bootstrap’s functions like shade-color() or mix() throw an error:
Steps to reproduce
@import "bootstrap/scss/bootstrap";
What we expected
We expected Bootstrap to allow var(--bs-primary) as a valid $primary so we can update theme colors dynamically via JavaScript (document.documentElement.style.setProperty('--bs-primaryColor', '#hexvalue');).
What actually happens
The Sass compiler treats var(--bs-primaryColor) as a string instead of a color, so functions like mix(), shade-color(), and tint-color() fail.
Environment
Additional context
We’ve tried workarounds like color-mix() in pure CSS and runtime shading in JavaScript, but those require rewriting Bootstrap utilities and components manually.
Here is repro on stackblitz
Would the Bootstrap team consider:
Supporting var() references for $theme-colors?
Or providing a recommended approach for dynamic theming without recompiling Bootstrap?
Beta Was this translation helpful? Give feedback.
All reactions