Skip to content

v6: Use token Sass map to customize CSS variables instead of Sass variables#41983

Open
mdo wants to merge 22 commits intov6-devfrom
v6-sass-css-tokens
Open

v6: Use token Sass map to customize CSS variables instead of Sass variables#41983
mdo wants to merge 22 commits intov6-devfrom
v6-sass-css-tokens

Conversation

@mdo
Copy link
Member

@mdo mdo commented Dec 31, 2025

This a cool idea IMO, but needs a little fleshing out. An annoying (to me) pattern we have in v6 (and v5 in a different way) is that we have Sass variables at the top of component files that are immediately mapped to CSS variables on the component classes, where we then only use the CSS variables. To customize with Sass, we'd do this:

@use 'bootstrap' as * with {
  $border-radius: .75rem,
  $primary: #f00,
  $dropdown-item-color: red,
};

Neat, but what if we cut out the middle man in our development—meaning no more Sass vars for the components—and instead use a token map that gets emitted onto the component class of our choosing? Something like this:

$tokens: () !default;

$dropdown-tokens: map.merge(
  (
    --dropdown-color: var(--fg-body),
    --dropdown-bg: var(--bg-body),
  ),
  $tokens
);

.dropdown-menu {
  @each $prop, $value in $dropdown-tokens {
    #{$prop}: #{$value};
  }
  // styles
}

Which would allow us to do this instead:

@use `bootstrap/dropdown` as * with {
  $tokens: (
    --dropdown-item-color: #f000,
    --dropdown-item-bg: #0f0,
  )
}

Of course we'd still have some Sass variables—it's how we generate our colors and more. But for the realtime customization that we all want out of a library like this, I think it could be fun. This keeps all the really powerful parts of Sass—functions, mixins, loops, maps, etc—and gives a singular avenue for customization regardless of compilation method.

  • Using Sass? Modify CSS variables (in a Sass map) using @use
  • Using CSS only? Modify CSS variables anyway you wish with vanilla CSS

And for folks who want more power—like customizing the utility API, toggling global options, etc—Sass is still there to do what you want at any point.

Potentially fun idea, needs feedback.

@mdo mdo requested a review from a team as a code owner December 31, 2025 08:06
@mdo mdo added this to v6.0.0 Dec 31, 2025
@github-project-automation github-project-automation bot moved this to Inbox in v6.0.0 Dec 31, 2025
@mdo mdo force-pushed the v6-sass-css-tokens branch 2 times, most recently from 938560f to 49a9e54 Compare January 6, 2026 06:41
@mdo mdo requested a review from a team as a code owner January 9, 2026 04:15
@mdo mdo force-pushed the v6-sass-css-tokens branch 2 times, most recently from c863123 to d64c716 Compare January 9, 2026 17:31
@pricop
Copy link

pricop commented Feb 21, 2026

I had a look over this proposed change, this looks amazing.

It feels much cleaner to have (almost) everything related to customizing a component in a map, it adds this feeling of component-scope configuration to it, I love this change.

I'd love to see this being pushed forward. +1 from me.

@mdo mdo force-pushed the v6-sass-css-tokens branch from 238fb1e to 2806237 Compare February 21, 2026 20:49
@mdo mdo force-pushed the v6-sass-css-tokens branch from d9fbdde to 6d2db4c Compare February 26, 2026 04:53
@mdo
Copy link
Member Author

mdo commented Feb 26, 2026

Test failure due to Coveralls outage: https://status.coveralls.io.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

Status: Inbox

Development

Successfully merging this pull request may close these issues.

2 participants