Spectre.css
  • Introduction
  • ❤ Benefits
  • General concepts
  • Getting started
    • Skeleton
    • Installation
      • npm
    • Usage
  • Variables
    • Color scheme
    • CSS variable name
    • Using CSS variables
    • Colors
      • Settable SCSS
      • Based on settable SCSS
      • CSS variable color
      • Using CSS variable color
      • Color code
    • Other
  • CSS Color Classes
    • Background colors
    • Label colors
    • ⚠ Text colors
    • ⚠ Toast colors
  • Function
    • Color
      • alpha-var()
      • color()
      • color-name()
      • hsla-color()
      • hue-var()
      • lightness-level-var()
      • lightness-var()
      • saturation-var()
    • Var
      • css-var()
      • get-var()
      • size-var()
      • unit-var()
      • var-adjust()
      • var-name()
      • var-negative()
      • var-unit()
    • get-border()
    • get-from-list()
    • important()
    • map-get-default()
    • strip-unit()
    • typeof()
  • Mixin
    • Border
      • border()
      • border-hover()
      • border-variant()
    • Color
      • background()
      • background-color()
      • bg-color-variant()
      • color-active()
      • color-focus()
      • color-hover()
      • color-picker()
      • color-visited()
      • set-color()
      • set-var-alpha()
      • text-color-variant()
    • Label
      • label-base()
      • label-variant()
      • label-class-variant()
    • Margin
      • margin-size-variants()
      • margin-variant()
    • Padding
      • padding-size-variants()
      • padding-variant()
    • Text
      • text-ellipsis()
    • Toast
      • toast-variant()
      • ⚠ toast-class-variant()
    • Var
      • set-var()
      • set-vars()
      • ⚠ define-color()
      • ⚠ define-color-based-on()
    • avatar-base()
    • box-shadow-side()
    • button-variant()
    • clearfix()
    • control-shadow()
    • disabled()
    • hide-scrollbar()
    • property()
    • shadow-variant()
    • transition()
    • z-index()
  • Change log
    • Keep a changelog
    • CHANGELOG.md
  • GIT
    • Commit
    • Semantic Versioning
  • License
    • MIT
  • Social
    • Gettr
    • Twitter
    • YouTube
  • Contact
    • ⋯ Chat
    • @ Email
    • ✆ Phone
  • Donate
    • ฿ Cryptocurrency
    • $ Fiat
Powered by GitBook
On this page
  1. Variables
  2. Colors

Using CSS variable color

PreviousCSS variable colorNextColor code

Last updated 2 years ago

To easily use color defined in four CSS variables with the help comes function, which takes six parameters: $name, $hue, $lightness, $saturation, $alpha, and $prefix, and returns color in form.

There is only $name parameter required, and the $hue $lightness $saturation default values are set to 0, $alpha default value is set to 1, and $prefix default value is equal to . So, it's very easy to insert the color into any style and change the default value of the CSS variable color, for example primary-color or primary-color-dark can be inserted as follows.

@use 'node_modules/@angular-package/spectre.css/functions' as *;
// or
@use 'node_modules/@angular-package/spectre.css/src/functions/color' as *; 

.primary-color {
  background: color('primary-color');
}

.primary-color-dark {
  background: color('primary-color-dark');
}

With the optional parameters, it's possible to inject primary-color lighter or darker by 30%, and it's useful, especially on mixing background with font color, and it works like and , but with the ability to change the value on the fly cause of the CSS variables.

@use 'node_modules/@angular-package/spectre.css/functions' as *;

.primary-color-lighter {
  background: color('primary-color', $lightness: -30%);
  color: color('primary-color', $lightness: 30%);
}

.primary-color-darker {
  background: color('primary-color', $lightness: -30%);
}

There are other SASS variables besides colors, that have equivalent CSS variables and default prefix s.

color()
hsla()
darken()
lighten()
$var-prefix