Yogesh Chauhan's Blog

What are partials in SCSS (Sass)?

in SCSS on May 24, 2021

What are partials?

Sass has few really good way to add file and divide your overall code in modules.

Partials are the the modules with their name starting with an underscore.

You use partials in SassScript when you want to skip the compilation of those files and just add those stylesheets as modules only.

Foe e.g.


_code.scss

When SassScript sees that initial underscore, it understands not to compile those files on their own.

You don’t need to add the underscore while importing those modules.

Just like this:


@import 'partials/code.scss';

What about index.scss?

SassScript automatically recognizes _index files from a folder.

So, if you add a folder name then it will look for _index.scss or _index.sass files and will load them automatically.


Example


// foundation/_fonts.scss
code {
  padding: .25em;
  line-height: 0;
}


// foundation/_lists.scss
ul, ol {
  text-align: left;

  & & {
    padding: {
      bottom: 0;
      left: 0;
    }
  }
}


// foundation/_index.scss
@use 'code';
@use 'lists';


// style.scss
@use 'foundation';


Can you load .css files in SCSS or Sass files?

Yes, SassScript can load a plain CSS file into SCSS or Sass files too. Although, they won’t be allowed any Sass special features so they can not expose any Sass members.

Just like this:


// code.css
code {
  padding: .25em;
  line-height: 0;
}


// style.scss
@use 'code';


Most Read

#1 How to check if radio button is checked or not using JavaScript? #2 Solution to “TypeError: ‘x’ is not iterable” in Angular 9 #3 How to add Read More Read Less Button using JavaScript? #4 How to uninstall Cocoapods from the Mac OS? #5 PHP Login System using PDO Part 1: Create User Registration Page #6 How to Use SQL MAX() Function with Dates?

Recently Posted

#Aug 15 Is PHP still good for back-end programming? #Aug 10 How to create a multisite network in WordPress? #Aug 3 How to create a circle that follows a cursor using JavaScript and CSS? #Aug 3 How to make a curtain slider using jQuery and CSS? #Aug 2 How to progressively load images and add a blurry placeholder? #Aug 1 How to create a placeholder loader (throbber) using CSS?
You might also like these
What’s a repository on Github?MiscellaneousHow to Install PHP Laravel on MacOS Catalina?PHPHow to Pop an Alert Box in PHP?JavaScriptThe Difference Between Arrays and Objects in JavaScriptJavaScriptThe substr() method in JavaScript and how it’s different from substring()JavaScriptSocial Media Colors: Sass VariablesMiscellaneous