The @use rule is the primary way to load another Sass file in the modern module system. This lesson covers namespace defaults, aliasing, loading built-in modules, and configuring a module's default variables with the with() clause.
What Does @use Do?
@use loads the variables, mixins, and functions from another Sass file (or a built-in module) and makes them available through a namespace. It is the direct, modern replacement for the legacy @import rule.
Because @use loads a file only once no matter how many other files reference it, it also prevents duplicated CSS output and eliminates a whole class of load-order bugs that were common with @import.
The default namespace, buttons, comes directly from the filename _buttons.scss (the underscore and extension are dropped).
@use Syntax Variations
@use 'path';
@use 'path' as alias;
@use 'path' as *;
@use 'path' with ($var: value);
@use 'path'; loads a file with the default namespace (its filename, without underscore or extension).
@use 'path' as alias; renames the namespace to something custom.
@use 'path' as *; removes the namespace, use only when collisions are truly impossible.
@use 'path' with (...) configures !default variables in the loaded file before it runs.
@use Rule Cheatsheet
The most common ways to load a module with @use.
Syntax
Namespace Result
When to Use
@use 'colors';
colors.$primary
Default, clearest for most projects
@use 'colors' as c;
c.$primary
Shorter alias for long filenames
@use 'colors' as *;
$primary
Rare, only when collisions are impossible
@use 'sass:math';
math.div(10, 2)
Loading a Sass built-in module
@use 'config' with ($radius: 8px);
n/a
Configuring a module's defaults on load
@use './buttons';
buttons.*
Relative path from the current file
Default and Custom Namespaces
By default, the namespace is the last component of the loaded file's path, with any leading underscore and file extension removed. If two files with the same name live in different folders, you must alias at least one to avoid a namespace clash.
If a partial defines variables using !default, you can override those defaults at the moment you load it using the with() clause, without editing the partial's source at all.
// _theme.scss
$primary: blue !default;
$radius: 4px !default;
// main.scss
@use 'theme' with (
$primary: #16a34a,
$radius: 8px
);
with() only works with variables marked !default, and only on the first load of that module.
Loading Built-in Modules
Sass ships several built-in modules, sass:math, sass:color, sass:list, sass:map, sass:string, and sass:meta, that you load the same way as your own files, using the sass: prefix.
Trying to override a variable with with() when it wasn't declared with !default in the source file, which raises a compile error.
Forgetting the namespace prefix and writing $primary instead of colors.$primary after loading with @use.
Placing a @use statement after other code in the file; all @use/@forward rules must come first, before any other statements.
Loading the same file twice with two different aliases, which works but makes the codebase inconsistent and harder to search.
Key Takeaways
@use loads another file's variables, mixins, and functions behind a namespace.
The default namespace comes from the filename, and can be renamed with as or removed with as *.
with() configures a module's !default variables at load time, without editing the source file.
Built-in Sass modules (sass:math, sass:color, and others) are loaded with @use just like your own files.
Pro Tip
Always place every @use and @forward statement at the very top of a file, before any variables or rules, Sass enforces this order and it keeps a file's dependencies easy to scan at a glance.
You now understand how the @use rule loads and configures modules. Next, learn the @forward rule for re-exporting members to consumers of your files.