Skip to content

carbon scss or css variables? #18087

Answered by janhassel
OmranAbazid asked this question in Help
Discussion options

You must be logged in to vote

I can't speak for the Carbon team but as a long time consumer, I would highly recommend using the Sass variables as they give you some advantages over the direct CSS custom properties:

1. Configuration

Aspects like the prefix can be configured globally. E.g.:

@use '@carbon/react/scss/config' with (
  $prefix: 'my-custom-prefix',
);

All Sass variables will automatically adapt to that.

2. Error handling

Sass will throw you a build error if for example $spacing-03 wouldn't exist. Using var(--cds-spacing-03) requires visual testing and can fail silently.

3. Fallbacks

At least for colors, the Sass variables include an appropriate fallback value in case the CSS custom property isn't set correct…

Replies: 1 comment 1 reply

Comment options

You must be logged in to vote
1 reply
@tay1orjones
Comment options

Answer selected by tay1orjones
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Help
Labels
None yet
3 participants