What'S The Difference Between @Import And @Use Scss Rules?

Scotty Moe

Updated on:

This article examines the distinction between the @import and @use SCSS rules and explores their respective functionalities and limitations.

The @import rule, which is currently being deprecated, will be discontinued after October 2022.

In contrast, the @use rule serves as a means to import variables, mixins, and functions in SCSS files. However, it does not import members with names starting with an underscore (_) or hyphen (-), and it only makes the imported members accessible locally.

Furthermore, @use does not pass imported members to subsequent imports, and @extends only applies within the imported files. By default, all imported members are namespaced.

The @import rule will be phased out once 80% of users adopt Dart Sass, and its elimination is expected to occur approximately one year after reaching this adoption rate. Notably, @import does not import private members designated with an underscore (_) or hyphen (-).

While both @import and @use are utilized for importing CSS and SCSS files, they differ in functionality and constraints.

What is it?

The difference between the @import and @use SCSS rules lies in their functionality and deprecation status.

While @import is used to import stylesheets and will be deprecated in favor of @use and @forward, @use is used to import variables, mixins, and functions, and does not import members starting with an underscore or hyphen.

Additionally, @use only makes imported members available locally and does not pass them to future imports.

@extends, a rule used for inheritance, only applies up the chain in imported files and does not extend files that import the current one.

All imported members are namespaced by default when using @use.

On the other hand, @import will be deprecated when 80% of users are using Dart Sass, and it will likely be removed at least a year after reaching an 80% adoption rate.

Differences and Usage

One distinction lies in the deprecation of @import in favor of @use and @forward, with the support for @import expected to be dropped by October 2022 at the latest.

@use is used to import variables, mixins, and functions, but it does not import members starting with an underscore (_) or hyphen (-). Additionally, @use only makes imported members available locally and does not pass them to future imports.

When it comes to @extends, it only applies up the chain in imported files and does not extend files that import the current one. Moreover, all imported members are namespaced by default.

On the other hand, @import is used to import stylesheets in a project, but it will be deprecated when 80% of users are using Dart Sass. It does not import private members, which start with an underscore (_) or hyphen (-).

Limitations and Considerations

A key factor to consider when using @use and @import in SCSS is their limitations and considerations.

These rules have specific use cases and should not be used for certain purposes.

Firstly, they should not be used for asking questions, seeking help, making statements based on opinion, or providing clarifications or responses to other answers.

Additionally, @use and @import are not suitable for browsing other questions or importing regular CSS files. They also cannot be used to import files from different folders or import SCSS files without errors.

Moreover, @use and @import should not be used for confusion on Sass and SCSS, importing CSS files as SCSS files, or importing regular CSS files in SCSS files.

Lastly, they are not intended for importing SCSS files as modules or global stylesheets.

Leave a Comment