Create a Button Variant

Spruce CSS generates the button variants from colors. Add a few colors and one line of Sass per variant.

1. Add the Colors

Declare the colors under the btn group of the $colors map with a prefix you can reference later (here: dark-):

@use 'sprucecss/scss/spruce' with (
  $colors: (
    'btn': (
      'dark-background': hsl(205deg 100% 2%),
      'dark-background-hover': hsl(205deg 100% 12%),
      'dark-foreground': hsl(0deg 0% 100%),
    ),
  ),
);

These three are enough. For more control, add any of the optional keys:

KeyUsed by
dark-foreground-hoverThe solid variant hover text.
dark-focus-ringThe focus ring of every variant.
dark-shadowGenerates the .btn--dark-shadow modifier.
dark-outline-border, dark-outline-foreground, dark-outline-background-hover, dark-outline-foreground-hoverThe outline variant.
dark-soft-background, dark-soft-background-hover, dark-soft-foregroundThe soft variant (otherwise mixed from the background).
dark-ghost-foreground, dark-ghost-background-hoverThe ghost variant (otherwise mixed from the background).

Spruce decides at compile time which optional keys exist, so add them to the base $colors map (a style preset or theme can then overwrite their values).

2. Generate the Classes

@use 'sprucecss/scss/spruce' as *;

.btn--dark { @include btn-variant('dark'); }
.btn--outline-dark { @include btn-variant-outline('dark'); }
.btn--soft-dark { @include btn-variant-soft('dark'); }
.btn--ghost-dark { @include btn-variant-ghost('dark'); }

3. Use Them

<a href="#" class="btn btn--dark">Get started</a>
<a href="#" class="btn btn--outline-dark">Learn more</a>
<button type="button" class="btn btn--soft-dark">Save draft</button>
<button type="button" class="btn btn--ghost-dark">Cancel</button>

Dark Mode

If the dark mode needs different values, add the same keys to $dark-colors. The variants read the colors through custom properties, so no extra CSS is needed.

See the buttons page and the button mixins for all options.

Documentation

Learn about Spruce CSS through our extensive documentation.

Components

Explore our UI library of accessible components built with Spruce CSS.

Blocks and Pages

Full-width page blocks and complete page templates, ready to copy.

Find us on GitHub

Did you find a bug? Have an idea or a question? Please open an issue to help us develop the project.