Open In App

Why to put “_” in front of filename in SCSS ?

Last Updated : 28 Nov, 2019
Improve
Improve
Like Article
Like
Save
Share
Report

When we add “_” in front of the SCSS file, it means that it is partial for SCSS. When the compiler gets any SCSS files starting with “_”, it simply ignores the file. If you want this partial for SCSS to be included for styles, you must use @import. The advantage of using partials is that you can use style files to organize your code and all the files would be compiled on a single file. The purpose of partial SCSS is to keep your styles separated into logical sections.
In the end, we want one SCSS file to have complied whereas we can have many logical partial SCSS files.

Syntax:

@import filename;

Note: While importing we don’t put “_”, just the file name.

Examples 1: Let’s create a colors file _colors.scss




$first-color: blue;
$second-color: yellow;
  
// let's include it in main
// SCSS file, style.scss
  
@import "colors"
body {
  color: $first-color;
  background: $second-color;
}


Output:

body {
  color: blue;
  background: yellow; 
}

Examples 2: Let’s create a colors file _font.scss




$font: arial;
$color: red;
  
// Let's include it in main
// SCSS file, style.scss
  
@import "font";
body {
  font: 100% $font;
  color: $color;
}


Output:

body {
  font: 100% arial;
  color: red;
}

Like Article
Suggest improvement
Previous
Next
Share your thoughts in the comments

Similar Reads