SCSS Partials: What They Are and How to Load Them

Quick Summary
- An SCSS file named with a leading underscore, such as _variables.scss, is a partial that Sass never compiles into its own CSS file.
- Load partials into a main file such as style.scss with @use, leaving out the leading underscore and the file extension.
- With @use, partial members are namespaced by default, such as variables.$name, while the older @import is being phased out by Sass.
SCSS partials are files whose names start with an underscore, such as _variables.scss or _mixins.scss. Partials usually hold variables, mixins or the styles for one part of a site, and you pull them into a main file like style.scss.
How partials differ from main files
The underscore tells Sass not to compile the file on its own. A partial doesn’t generate a CSS file or a CSS map file. A main file such as style.scss, without the underscore, compiles to style.css, plus a map file if source maps are turned on.
To use a partial, load it from the main file with @use, or the older @import, which Sass is phasing out. You can leave out the underscore and the file extension: @use 'variables'; loads _variables.scss. With @use, the partial’s members are namespaced by default, so a variable is referenced as variables.$name.
This lets you split your styles into small, organized files and still ship a single CSS file. The 7-1 Sass folder structure is one common way to organize those partials.
Related articles
- setting the Live Sass Compiler output folder: compile your main file into a separate CSS folder in VS Code
