Sass — Partials
What are partials?
Files starting with _ are not compiled to CSS:
scss/
├── _variables.scss
├── _mixins.scss
├── _base.scss
├── _components.scss
└── main.scss
Creating partials
// _variables.scss
$primary: #3498db;
$font-size: 16px;
// _mixins.scss
@mixin flex-center {
display: flex;
justify-content: center;
align-items: center;
}
Importing partials
// main.scss
@use 'variables';
@use 'mixins';
@use 'base';
@use 'components';
Recommended structure
scss/
├── abstracts/
│ ├── _variables.scss
│ ├── _mixins.scss
│ └── _functions.scss
├── base/
│ ├── _reset.scss
│ └── _typography.scss
├── components/
│ ├── _buttons.scss
│ ├── _cards.scss
│ └── _forms.scss
├── layout/
│ ├── _header.scss
│ ├── _footer.scss
│ └── _grid.scss
└── main.scss
Index file
// components/_index.scss
@forward 'buttons';
@forward 'cards';
@forward 'forms';
Benefits
- Organization: Related styles grouped together
- Maintainability: Easy to find and update styles
- Reusability: Share between projects
- Collaboration: Multiple devs work on different files
Mini Practice
- Create a _variables.scss partial
- Create a _mixins.scss partial
- Build an index file to forward all modules
- Organize a project with folder structure
Up Next
Continue with Build Process — integrating Sass into your workflow.
Related Topics
Frequently Asked Questions about Partials
What is Partials in Sass?
Partials is a fundamental concept in Sass. This lesson explains it step by step with clear examples, making it easy for beginners to understand.
How do I learn Partials?
Start by reading the explanation above, then try the code examples. Practice by modifying the examples and experimenting with different values. Hands-on practice is the best way to learn Partials.
Why is Partials important in Sass?
Partials is essential for Sass development. Understanding this concept will help you write better code and solve real-world problems more effectively.