Sass Partials and Import
Sass Partials and Import
Sass Partials and Import help you break a large stylesheet into smaller, reusable, and well-organized files.
This is extremely useful in large projects and team environments.
What Are Sass Partials?
A partial is a Sass file whose name starts with an underscore (_).
Sass knows that these files are not compiled into separate CSS files.
Example Partial File
✔ The underscore tells Sass this file is a helper file.
Creating a Partial
_variables.scss
_buttons.scss
Importing Partials (@import)
Use @import to include partials into a main file.
style.scss
✔ No underscore (_)
✔ No file extension (.scss)
Folder Structure (Best Practice)
Import Order Matters
Variables & mixins should be imported before they are used.
Difference Between CSS @import and Sass @import
CSS @import |
Sass @import |
|---|---|
| Creates extra HTTP requests | No extra requests |
| Slower performance | Faster |
| Limited usage | Full Sass support |
Modern Alternative: @use (Recommended)
⚠️ Sass @import is deprecated (still works).
Using @use
✔ Prevents global scope pollution
✔ More maintainable
@forward (Advanced)
Used with @use to re-export files.
📌 Real-Life Example
main.scss
Compiled into:
📌 Summary of Sass Partials & Import
✔ Partials start with _
✔ Use @import to combine files
✔ Improves maintainability
✔ Prefer @use for new projects
