-1

I have a number of CSS variables containing color values. I'd like to define these in HSL format, but can I let Sass convert these to hex values?

Input:

:root {
  --dark: hsl(210, 50%, 13%);
}

Output:

:root {
  --dark: #112132;
}

1 Answer 1

0

According to the SASS documentation SASS has a build-in module to handle colors in hsl format:

https://sass-lang.com/documentation/modules/

From documentation:

Global Functions

hsl($hue $saturation $lightness)
hsl($hue $saturation $lightness / $alpha)
hsl($hue, $saturation, $lightness, $alpha: 1)
hsla($hue $saturation $lightness)
hsla($hue $saturation $lightness / $alpha)
hsla($hue, $saturation, $lightness, $alpha: 1) //=> color
Sign up to request clarification or add additional context in comments.

2 Comments

That does not result in hex values when used for CSS variables.
I guess I slightly misread your post. I found a post with the summary SASS variables compile at runtime, CSS custom properties compile when they're used. - https://dev.to/nicm42/combining-sass-variables-with-css-custom-properties-5hj7 - seems that it does not work that way.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.