2021 update

The Sass team discourages the continued use of the @import rule. Sass will gradually phase it out over the next few years, and eventually remove it from the language entirely. Prefer the @use rule instead.

So as per the situation here , the code should be changed from

@import 'path/to/main.scss' //Note: make sure that you name your sass partials starting with an underscore(_), this way sass knows that its not meant to be compiled to a css file and you also don't need to include the extension as seen here, instead change it

to

@use 'path/to/main' as m //where 'm' is a reference variable or namespace to your partial.which BTW is optional but recommended.

You can find more about it here: Sass-docs/imports

Answer from shaderone on Stack Overflow
🌐
Sass
sass-lang.com › documentation › at-rules › import
Sass: @import
The CSS in nested imports is evaluated like a mixin, which means that any parent selectors will refer to the selector in which the stylesheet is nested. ... // _theme.scss ul li { $padding: 16px; padding-left: $padding; [dir=rtl] & { padding: { left: 0; right: $padding; } } }
Discussions

Can i use mixins defined in a partial that is imported in the main scss file in another partial?
You have to import the mixins before importing navigation.scss. So the order inside the style file matters. More on reddit.com
🌐 r/webdev
10
1
September 13, 2024
Can't @use mixin, but can @import
You switched accounts on another tab or window. Reload to refresh your session. ... If I @import it, everything is fine. If I @use it, then it doesn't come through. For example, this fails, but if I change the @use to @import, it succeeds: @use 'mixins'; .bg { @include bg_img("photo.jpg"); } Side point: the file ... More on github.com
🌐 github.com
9
May 6, 2020
gulp - Can SASS mixins and variables sit in different files? - Stack Overflow
Hi I am trying to organise my sass files into separate chunks on a project using GULP. However when I import my mixins and variables in separate files: File:variables.scss //first import variable... More on stackoverflow.com
🌐 stackoverflow.com
sass - import content of scss file using mixin - Stack Overflow
Is there any way to import the content of a scss file into another scss file using mixins? Something like this: // media.scss @mixin media($width, $url) { @media (min-width:$width) { @import url($url); } }; @mixin small($url) { @include media(576, $url); }; //main.scss @import '../../style... More on stackoverflow.com
🌐 stackoverflow.com
🌐
Sass
sass-lang.com › documentation › at-rules › mixin
mixin and @include
A mixin can pass arguments to its content block the same way it would pass arguments to another mixin by writing @content(<arguments...>). The user writing the content block can accept arguments by writing @include <name> using (<arguments...>).
🌐
Reddit
reddit.com › r/webdev › can i use mixins defined in a partial that is imported in the main scss file in another partial?
r/webdev on Reddit: Can i use mixins defined in a partial that is imported in the main scss file in another partial?
September 13, 2024 -

I have three files:

  • style.scss

  • _mixins.scss

  • _navigation.scss

obviously, in _mixins.scss i have my mixins defined. In style.scss i then import these mixins with u/use 'mixins';. I now also have another partial called _navigation.scss that i also imported into the main scss file using u/use 'navigation';. I now want to use a mixin defined in the mixins partial, in the navigation partial. But when i try to do this i get an Error: Undefined mixin.

Is what i am trying to do not possible? If so, how would i use a mixin defined in _mixins.scss in another partial?

🌐
Sass
sass-lang.com › documentation › at-rules › use
Sass: @use
If you find yourself wanting to configure many variables at once, pass maps as configuration, or update the configuration after the module is loaded, consider writing a mixin to set your variables instead and another mixin to inject your styles. ... // _library.scss $-black: #000; $-border-radius: 0.25rem; $-box-shadow: null; /// If the user has configured `$-box-shadow`, returns their configured value. /// Otherwise returns a value derived from `$-black`. @function -box-shadow() { @return $-box-shadow or (0 0.5rem 1rem rgba($-black, 0.15)); } @mixin configure($black: null, $border-radius: null, $box-shadow: null) { @if $black { $-black: $black !global; } @if $border-radius { $-border-radius: $border-radius !global; } @if $box-shadow { $-box-shadow: $box-shadow !global; } } @mixin styles { code { border-radius: $-border-radius; box-shadow: -box-shadow(); } }
🌐
GitHub
github.com › sass › sass › issues › 2858
Can't @use mixin, but can @import · Issue #2858 · sass/sass
May 6, 2020 - You switched accounts on another tab or window. Reload to refresh your session. ... If I @import it, everything is fine. If I @use it, then it doesn't come through. For example, this fails, but if I change the @use to @import, it succeeds: @use 'mixins'; .bg { @include bg_img("photo.jpg"); } Side point: the file ...
Author   dakom
Top answer
1 of 3
16

The short answer is you dont have to import them into everyfile that might include them. However there does need to be a relationship somewhere, and how you do this depends on whether or not you are looking to build one single final CSS file - or a series of individual files.

If you want the former, you could consider having a master import file that does little more than import all the appropriate *.scss files, and have this be the main SASS file your gulp build script looks to compile.

You'll need to take care to import files in the correct order - so no importing a file that uses a mixin before the file that defines the mixin has been imported it's self.

So for example - personally I work with a main.scss file that is structured as

@import "common/_variables.scss";
@import "common/_mixins.scss";


// Now import the files that might use these vars/mixins
@import "common/_buttons.scss";

which is built via gulp to create css/main.css.

Should you want a series of CSS files - i.e. buttons.css, type.css, layout.css etc - then you would need to have the appropriate variables and mixin @import declarations in each file that calls them

2 of 3
2

I found the best solution for me with pre-concating SASS files with GULP.

Like in this example for STYLUS

gulp.src(config.projects.css.source)
    .pipe(sourcemaps.init())
    .pipe(mktimecss(__dirname+'/web'))
    .pipe(concat('styles'))
    .pipe(stylus({
        'include css': true,
        use: [nib()],
        // compress: true,
        linenos: false
    }))
    ...... and so on .......
Find elsewhere
🌐
Sass
sass-lang.com › guide
Sass: Sass Basics
This rule loads another Sass file as a module, which means you can refer to its variables, mixins, and functions in your Sass file with a namespace based on the filename. Using a file will also include the CSS it generates in your compiled output! ... // _base.scss $font-stack: Helvetica, ...
🌐
Stack Overflow
stackoverflow.com › questions › 70319006 › import-content-of-scss-file-using-mixin
sass - import content of scss file using mixin - Stack Overflow
In order to use a @mixin in SCSS, you have to use @include in the class selector in which you prefer to include those changes or those style rules. ... .menu { height: 4rem; border-bottom-left-radius: 10px; background-color: #202020; @include ...
🌐
KoderHQ
koderhq.com › tutorial › sass › mixin
Sass/SCSS Mixins, Functions & @includes Tutorial | KoderHQ
note Mixins aren’t globally available automatically. If your mixins live in separate files, they will need to be imported with @use into the document you want to use them in. It’s possible for us to include a mixin within the definition of another mixin.
🌐
W3Schools
w3schools.com › sass › sass_mixin_include.asp
Sass @mixin and @include
Then, you only need to specify the values that change when you include the mixin: SCSS Syntax: .myTips { @include bordered($color: orange); } Another good use of a mixin is for vendor prefixes.
Top answer
1 of 2
2

This is how you can implement mixin in your scss file:

@mixin mobile-md {
  @media (min-width: #{$breakpoint-mobile + 80}) {
    @content;
  }
}

And this is how you can use it in your code:

@include mobile-md {
  // Styles for screens larger than the mobile-md breakpoint
}

Let's understand all about mixin:

The provided code snippet is written in SCSS (Sassy CSS) and defines a mixin called mobile-md. A mixin in SCSS is a reusable block of code that can be included in other stylesheets using the @include directive.

Here's a breakdown of what the code does:

@mixin mobile-md { ... }: This line defines a mixin named mobile-md.

@media (min-width: #{$breakpoint-mobile + 80}) { ... }: This line specifies a media query that targets a minimum width equal to the value of the variable $breakpoint-mobile plus 80. The min-width condition is used to apply the styles within the media query only if the viewport width meets the specified criteria.

@content;: This line is a placeholder that will be replaced with the actual content of the mixin when it is included in other stylesheets using @include.

To better understand the code, we need to know the value of the variable $breakpoint-mobile. It seems that the value of this variable is expected to be a number representing a specific mobile breakpoint. The mixin mobile-md is intended to apply styles when the viewport width is larger than the mobile breakpoint plus 80 pixels.

By utilizing the mobile-md mixin with appropriate styles inside the @media block, you can create responsive designs that adapt to different screen sizes.

2 of 2
0

You don't want a class selector in your mixin.

That's why it's not applied.

@mixin special-button {
    background: $nav-background;
    height: 2.5em;
    border-radius: .8rem;
}

Change your mixin to the above and it will work. You almost had it. The way your selector would work based on the code you wrote would look for an element with class="excelGridCell" and then a nested element with a class="excelGridCell".

Also, I usually only use mixins for something that needs a parameter (potentially with a default value).

For this use case, you may want to just use @extend with some inheritance.

See section "Extend/Inheritance"

in https://sass-lang.com/guide

however this might be a bit of a religious war https://csswizardry.com/2014/11/when-to-use-extend-when-to-use-a-mixin/

🌐
GitHub
github.com › facebook › create-react-app › issues › 7777
Using url in SCSS mixin in another file doesn't import files correctly · Issue #7777 · facebook/create-react-app
October 4, 2019 - Using an SCSS mixin (located in another file) that uses the url function makes the file unable to be found. Example: // src/scss/mixins.scss @mixin next-gen-image ($file-name, $fallback-ext) { .webp-supported & { background-image: ...
Author   Dakkers
🌐
TutorialsTeacher
tutorialsteacher.com › sass › sass-mixins
Sass - Mixins
@include a-button.scss //assuming a-button.scss is the name of above mixin file .menu-button { @include a-button; }
🌐
Stack Overflow
stackoverflow.com › questions › 58879163 › include-a-mixin-in-all-scss-files
sass - include a mixin in all scss files - Stack Overflow
So I have a react application that has a main 'App.scss' file that is basically only including other scss files like this: @import "./base/mixins.scss"; @import "./components/hamburger.scss"; @imp...
🌐
Andyp
andyp.dev › posts › using-mixins-includes-and-imports-in-scss-sass
Using Mixins, Includes and Imports in SCSS / SASS | Andyp.dev
April 4, 2020 - Also notice that you don't need to specify the full filename when importing, you can reference 'partial/_menu' instead of 'partial/_menu.scss'. Mixins are sets of rules defined within your Scss files, that allow you to define styles that can be re-used throughout the stylesheet.
🌐
freeCodeCamp
freecodecamp.org › news › how-to-pass-arguments-to-mixins
How to Use Mixins in Sass and Pass Arguments – With Code Examples
September 8, 2025 - First we define a mixin using the @mixin at-rule. Then we give it a name – choose whatever you think will fit what you're gonna be using it for. Add your CSS properties. By simply using @include you pass it to the mixin block.
🌐
GitHub
github.com › sass › sass › issues › 2470
Declare mixins and functions within mixin · Issue #2470 · sass/sass
February 6, 2018 - @mixin _someMixin-internal () { ... } @function _someMixin-internal () { ... } @mixin someMixin () { ... @include _someMixin-internal(_someMixin-internal()); ''' }
Author   ArmorDarks
🌐
Reddit
reddit.com › r/angular › how do you work with scss variables and mixins in angular component.scss?
r/angular on Reddit: How do you work with SCSS variables and Mixins in Angular component.scss?
October 13, 2021 -

We all know that Angular has component-specific SCSS file for styling which is really a good thing. We mostly write our common/global styles in styles.scss file or any other file which is imported into styles.scss file. Suppose we have variables.scss and mixins.scss file. These files contain variables and mixins. whenever we need to use them we can import them into styles.scss file to use them in that file. But, if we need those variables and mixin in our specific components we need to import them again into our components.

  1. Doesn't it have any performance issues? like redundant variables and mixins in components as well.

  2. Isn't it like building/bundling variables and mixins multiple times for each component we have imported into?

  3. isn't this increasing the build/bundle size for each component and global component as well?

My question is what is the best way to access variables and mixins globally or locally (by importing in component) without having any performance issues and bundle size issues?