</>
Skip to content
Sass lessons (8/28)

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

  1. Create a _variables.scss partial
  2. Create a _mixins.scss partial
  3. Build an index file to forward all modules
  4. 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.