Installation

Spruce CSS is built on Sass; to get its full potential, you should use it with Sass. You can load the compiled CSS too, but you will lose the configuration and the helpers.

Install with NPM

npm install sprucecss --save

Install with Yarn

yarn add sprucecss

Use the Compiled CSS

The package contains two compiled bundles in the css folder, each in a regular and a minified version:

FileWhat’s inside
spruce.css, spruce.min.cssThe default styles in custom property mode.
spruce.complete.css, spruce.complete.min.cssEverything: the dark mode, every style preset, the layout and text utilities.

Load them from a CDN:

<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/sprucecss@3/css/spruce.min.css">
<!-- or, with dark mode and the styles: -->
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/sprucecss@3/css/spruce.complete.min.css">

Or download the latest release and use the files from the css folder.

Using Spruce CSS with Sass

The manageability of Spruce CSS comes from its Sass features, variables, mixins, and functions. You should use the preprocessor for the proper workflow (e.g., overwriting the default variables).

With the help of the mixins and functions, you can write code easier.

Import It With @use

To import it into your project, use Sass’s @use rule, the module-based successor of @import. Unlike @import, you must @use Spruce in every file where you want to access its variables, functions or mixins.

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

Namespacing

The @use rule loads the mixins, functions, and variables without a namespace, so you can simply refer to anything by its name:

.section {
  @include layout-stack('m');
}

We include the layout-stack mixin that will make a simple stacked layout.

If you prefer the namespaces, leave the as * part out and use the following:

@use 'sprucecss/scss/spruce';

.section {
  @include spruce.layout-stack('m');
}

Resolve the Package

Tell Sass where to find the package. The simplest is the load path:

sass --load-path=node_modules src/scss:dist/css

With Sass’s Node package importer (--pkg-importer=node), you can use the pkg: URL, which reads the sass entry point of the package:

@use 'pkg:sprucecss' as *;

Based on your build tool, you may need the tilde ~ character at the start of the path (an old Webpack shorthand for node_modules). Vite and most modern setups don’t need it.

Configure Once

Sass lets you configure a module only once, at its first @use. Keep the configuration in one file and load it first:

// config/_config.scss
@use 'sprucecss/scss/spruce' with (
  $settings: (
    'css-custom-properties': true,
  ),
);
// main.scss
@use 'config/config';
@use 'sprucecss/scss/spruce' as *;

@include generate-styles;

Load Styles

Importing Spruce means you load its variables, functions, and mixins. To use its styles, you must include them explicitly with a mixin.

To load the styles, you need to include a generator mixin. A generator (a naming convention in Spruce CSS only) mixin is a wrapper mixin whose goal is to generate a specified style, usually once in your project. These are complete declarations with selectors, so you can’t use them inside code blocks.

You can control the flow of the style generation in a lot of ways (for more information, please visit our Generators page), but there is one main mixin to use:

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

@include generate-styles;

Compiling Sass

Depending on your development setup, using Sass could be a burden. We think that Sass is a handy tool and easy to use. Compiling is one of the more significant barriers; for this reason, we wrote a guide about a simple Sass compile setup.

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.