Partial files help organize your styles into smaller pieces. The underscore prefix tells Sass not to create a separate CSS file for that part.
Partial files with underscore prefix in SASS
// Filename: _partial.scss // Use underscore at the start of the filename // Import in main file without underscore @use 'partial';
The underscore (_) at the start means Sass treats it as a partial file.
You do not compile partial files directly; instead, you import them into main files.
// _colors.scss $primary-color: #3498db;
// _buttons.scss @use 'colors'; .button { background-color: colors.$primary-color; color: white; padding: 1rem; }
// main.scss @use 'colors'; @use 'buttons';
This example shows two partial files: one for colors and one for button styles. The main file imports both. Sass compiles all styles into one CSS file without creating separate CSS files for the partials.
// _colors.scss $primary-color: #3498db; // _buttons.scss @use 'colors'; .button { background-color: colors.$primary-color; color: white; padding: 1rem; border-radius: 0.5rem; } // main.scss @use 'colors'; @use 'buttons';
Always start partial filenames with an underscore (_) to mark them as partials.
Partial files are not compiled alone; they must be imported into a main Sass file.
Use @use or @import (deprecated) to include partials in your main file.
Partial files start with an underscore to avoid generating separate CSS files.
They help organize and reuse styles efficiently.
Import partials into main Sass files to compile all styles together.
Practice
_variables.scss)?Solution
Step 1: Understand Sass partial naming
Files starting with an underscore are called partials and are not compiled into separate CSS files.Step 2: Purpose of partial files
They are meant to be imported into other Sass files to organize code without creating extra CSS files.Final Answer:
To mark it as a partial file that won't compile to a separate CSS file -> Option AQuick Check:
Partial files start with underscore = no separate CSS file [OK]
- Thinking underscore hides the file from compiler
- Assuming underscore means only variables inside
- Believing underscore speeds up browser loading
_mixins.scss into another Sass file?Solution
Step 1: Understand import syntax for partials
When importing partials, omit the underscore and file extension.Step 2: Apply correct import format
So to import_mixins.scss, write@import 'mixins';without underscore or extension.Final Answer:
@import 'mixins'; -> Option CQuick Check:
Import partials without underscore or extension [OK]
- Including underscore in import path
- Adding .scss extension in import
- Using incorrect quotes or syntax
_colors.scss contains:$primary-color: blue;
main.scss contains:@import 'colors';
body { color: $primary-color; }What will be the color of the text in the compiled CSS?
Solution
Step 1: Check variable definition in partial
The_colors.scssfile defines$primary-color: blue;.Step 2: Confirm import and usage in main.scss
Main file importscolorspartial and uses$primary-colorin body color.Final Answer:
blue -> Option BQuick Check:
Imported variable used correctly = blue text [OK]
- Forgetting to import partial
- Using variable before import
- Expecting partial to generate separate CSS
_buttons.scss but when you compile your main Sass file, styles from _buttons.scss are missing. What is the most likely cause?Solution
Step 1: Check partial file naming
Partial files must start with underscore;_buttons.scssis correct.Step 2: Verify import statement in main file
If styles are missing, likely the partial was not imported using@import 'buttons';.Final Answer:
You forgot to importbuttonspartial in the main Sass file -> Option DQuick Check:
Missing import = missing styles [OK]
- Removing underscore from partial filename
- Expecting partials to compile alone
- Renaming partial to .css instead of .scss
_reset.scss, _typography.scss, and _layout.scss. How should you structure your main Sass file to compile all styles into one CSS file?Solution
Step 1: Understand import syntax for multiple partials
Each partial is imported separately without underscore or extension.Step 2: Write imports correctly in main file
Use separate@importstatements for each partial:@import 'reset';,@import 'typography';,@import 'layout';.Final Answer:
@import 'reset'; @import 'typography'; @import 'layout'; -> Option AQuick Check:
Separate imports without underscore or extension [OK]
- Including underscore or .scss in import
- Trying to import multiple files in one statement with commas
- Renaming partials to .css files
Ready to prove it?
Pass the test and this pattern moves unknown
