SASS Partials
Jessica Chappell
Posted on July 20, 2021
Partials are an incredibly useful feature of SASS. They allow you to create snippets of CSS that you can import into other SASS files for modularity.
You can denote a partial file with a leading underscore like so:
- styles
- base.scss
- _colors.scss
By themselves, these files won't be generated into CSS. However, variables defined in partial files will be replaced by their actual values at build time.
For example, you could have a partial file that looks like this:
// _colors.scss
$primary-color: black;
and import the value into a regular .scss file like so:
// base.scss
@import "colors";
.button {
color: $primary-color;
}
Note how you don't need the leading underscore or the file extension when importing a partial!
Then when the css is transpiled the resulting file will look like this:
// base.css
.button {
color: black;
}
Posted on July 20, 2021
Join Our Newsletter. No Spam, Only the good stuff.
Sign up to receive the latest update from our blog.