Sass @use Rule

Beginner
⏱️ 14 min read
📚 Updated: Jul 2026
🎯 5 Examples
Dart Sass 1.23+

What You’ll Learn

The Sass @use rule loads other stylesheets as modules. You get their CSS once, plus namespaced variables, functions, and mixins. This page covers namespaces, as *, with configuration, private members, partials, and five compiled examples.

01

Load

@use "url"

02

Namespace

mod.$var

03

Alias

as c / as *

04

Configure

with (…)

05

Privacy

$-private

06

Practice

5 examples

What Is @use?

Official docs: the @use rule loads mixins, functions, and variables from other Sass stylesheets, and combines CSS from multiple stylesheets together. Stylesheets loaded by @use are called modules. Sass also provides built-in modules like sass:math and sass:string.

  • CSS from a module is included exactly once, no matter how often it is loaded.
  • Members are namespaced by default—easy to see where $radius came from.
  • @use rules must come before other rules (except @forward).
  • You may declare variables before @use to help configure modules.
  • Requires Dart Sass 1.23+ (not LibSass / Ruby Sass).
💡
Beginner tip

Think of @use as borrowing a labeled toolbox: @use "src/corners" gives you corners.rounded, not a pile of global names mixed with everything else.

📝 Syntax

styles.scss
@use "url";
@use "url" as alias;
@use "url" as *;
@use "url" with (
  $variable: value
);
@use "url" as alias with (
  $variable: value
);

Parts of the rule

PartMeaning
"url"Module path (extension optional). Use forward slashes.
as aliasCustom namespace instead of the file/folder name
as *No namespace—members join the current file
with (…)Override !default variables when the module first loads

📦 Loading Members

Official docs: access variables, functions, and mixins with namespace.$var, namespace.fn(), or @include namespace.mixin. By default, the namespace is the last component of the module’s URL.

styles.scss
// src/_corners.scss
$radius: 3px;

@mixin rounded {
  border-radius: $radius;
}

// style.scss
@use "src/corners";

.button {
  @include corners.rounded;
  padding: 5px + corners.$radius;
}
  • Members loaded with @use are only visible in the file that loads them.
  • Other files must write their own @use if they need the same members.
  • To re-export many modules from one entry file, use @forward.
💡
Fun fact

Because namespaces avoid collisions, you can keep simple names like $radius inside a module—unlike old @import habits that pushed long prefixes such as $mat-corner-radius.

🏷️ Choosing a Namespace

WriteAccess as
@use "src/corners";corners.$radius
@use "src/corners" as c;c.$radius
@use "src/corners" as *;$radius (no prefix)

Official docs: use as * mainly for stylesheets you control. Third-party modules may add members later and cause name conflicts.

🔒 Private Members

Official docs: start a name with - or _ to keep it private. Private members work inside the defining file but are not part of the module’s public API.

styles.scss
// src/_corners.scss
$-radius: 3px;

@mixin rounded {
  border-radius: $-radius;
}

// style.scss
@use "src/corners";

.button {
  @include corners.rounded;
  // Error: corners.$-radius is not visible outside _corners.scss
}

⚙️ Configuration With with

Official docs: define variables with the !default flag, then load the module with @use "…" with ($name: value). Configured values override the defaults.

  • A module keeps the same configuration even if loaded again.
  • @use … with can only be used once per module—the first load.
  • If you also need a custom namespace: @use "…" as alias with (…) (as before with).
💡
Advanced alternative

Official docs: for flexible themes, prefer a configure mixin plus a styles mixin instead of giant with maps.

🔍 Finding the Module

  • Extensions are optional: @use "variables" loads .scss, .sass, or .css.
  • Use forward slashes in URLs (even on Windows).
  • URLs are case-sensitive.
  • Relative paths are checked first; load paths are a fallback.
  • Partials start with _ (as in _code.scss); omit the underscore when loading.
  • A folder’s _index.scss loads when you @use "folder".

🔁 @use vs @import

@use@import
NamespaceYes (by default)No—everything is global
CSS includedOnce per moduleCan duplicate
Member visibilityOnly in the loading fileShared globally
Modern?Yes—prefer for new codeLegacy

🛠 Compatibility

This is about Sass compilers, not browsers. @use is resolved at compile time.

Implementation@use
Dart SassYes (since 1.23.0)
LibSassNo—use @import
Ruby SassNo—use @import

⚡ Quick Reference

GoalCode
Load a module@use "src/corners";
Use a mixin@include corners.rounded;
Read a variablecorners.$radius
Short alias@use "src/corners" as c;
No namespace@use "src/corners" as *;
Configure defaults@use "library" with ($black: #222);
Built-in module@use "sass:math";
Private member$-secret: 1px;

Examples Gallery

Multi-file samples show both the module and the loading file (as in the official docs). Open View Compiled CSS for verified output.

📚 Getting Started

Namespaces, aliases, and built-in-style member access.

Example 1 — Default Namespace

Load a partial and call its mixin plus variable.

styles.scss
// src/_corners.scss
$radius: 3px;

@mixin rounded {
  border-radius: $radius;
}

// style.scss
@use "src/corners";

.button {
  @include corners.rounded;
  padding: 5px + corners.$radius;
}

How It Works

The namespace comes from the last URL segment: corners. Padding becomes 5px + 3px8px.

Example 2 — Custom Namespace

Shorten a busy module name with as.

styles.scss
// src/_corners.scss
$radius: 3px;

@mixin rounded {
  border-radius: $radius;
}

// style.scss
@use "src/corners" as c;

.button {
  @include c.rounded;
  padding: 5px + c.$radius;
}

How It Works

Same module, shorter prefix. Handy when two modules would otherwise share a filename.

📈 Practical Patterns

Star import, configuration, and combining CSS-only modules.

Example 3 — as *

Bring members into the current scope without a prefix.

styles.scss
// src/_corners.scss
$radius: 3px;

@mixin rounded {
  border-radius: $radius;
}

// style.scss
@use "src/corners" as *;

.button {
  @include rounded;
  padding: 5px + $radius;
}

How It Works

Convenient for your own design tokens. Prefer a real namespace for libraries you do not control.

Example 4 — Configure With with

Override !default theme variables when the module first loads.

styles.scss
// _library.scss
$black: #000 !default;
$border-radius: 0.25rem !default;
$box-shadow: 0 0.5rem 1rem rgba($black, 0.15) !default;

code {
  border-radius: $border-radius;
  box-shadow: $box-shadow;
}

// style.scss
@use "library" with (
  $black: #222,
  $border-radius: 0.1rem
);

How It Works

$border-radius becomes 0.1rem. The shadow uses the configured $black (#222rgba(34, 34, 34, 0.15)).

Example 5 — Combine CSS Modules

Load multiple partials; each stylesheet’s CSS is emitted once.

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

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

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

// style.scss
@use "foundation/code";
@use "foundation/lists";

How It Works

Both modules contribute CSS. Nested & & expands to combinations of ul / ol. Loading either module again elsewhere would not duplicate this CSS.

🚀 Real-World Use Cases

  • Design tokens@use "tokens" for colors, spacing, and type.
  • Component libraries — load mixins like button.primary with clear namespaces.
  • Built-in helpers@use "sass:math", sass:string, sass:color.
  • Theming — configure !default variables once at the entry file.
  • Foundation CSS — split reset/base partials and compose them with @use.

🧠 How Compilation Works

1

Write @use at the top

Load modules before other style rules (except @forward).

Source
2

Resolve & configure

Find the file, apply with defaults once, build the namespace.

Compile
3

Use members & CSS

Call mixins/functions; include the module’s CSS a single time.

Emit
4

CSS ships

Browsers only see finished rules like border-radius: 3px.

⚠️ Common Pitfalls

  • Using @use after CSS rules — it must come first (with @forward / config vars as exceptions).
  • Forgetting the namespace — write math.abs(), not bare abs(), after @use "sass:math".
  • Configuring twicewith only works on the first load of a module.
  • as * collisions — limit star loads to your own files.
  • Backslashes on Windows — always use / in module URLs.

💡 Best Practices

✅ Do

  • Prefer @use (and @forward) over @import
  • Keep clear namespaces for shared libraries
  • Use partials (_file.scss) for modules
  • Configure themes once at the entry stylesheet
  • Hide internals with $-private names

❌ Don’t

  • Expect LibSass to support @use
  • Star-import every third-party library
  • Put @use in the middle of a stylesheet
  • Rely on @import for new projects
  • Expose every helper as a public member

Key Takeaways

Knowledge Unlocked

Five things to remember about Sass @use

Load modules once, with namespaces, on Dart Sass 1.23+.

5
Core concepts
🏷️ 02

Namespace

mod.$var

Access
⚙️ 03

Config

with (!default)

Theme
🔒 04

Private

$-name / _name

API
05

Once

CSS included once

Rule

❓ Frequently Asked Questions

The @use rule loads mixins, functions, and variables from another Sass stylesheet (a module) and combines CSS from multiple stylesheets. Each module’s CSS is included exactly once.
By default, use the last part of the URL as a namespace: @use "src/corners"; then corners.$radius, corners.rounded(), or @include corners.rounded.
It loads a module without a namespace so members are available as $radius or @include rounded. Official docs recommend this only for your own stylesheets to avoid name conflicts.
Define variables with !default in the module, then load with @use "library" with ($black: #222, $border-radius: 0.1rem). Configuration can only be applied the first time a module is loaded.
@use namespaces members, loads CSS once, and keeps members private to the loading file. @import is the older global system. Prefer @use (and @forward) for new code.
Dart Sass since 1.23.0. LibSass and Ruby Sass do not support @use—users of those implementations must use @import instead.
Did you know?

Official Sass docs note that members from @use stay local to the loading file—so you can always tell whether $radius came from corners or somewhere else by reading the namespace.

Conclusion

@use is the modern way to compose Sass: load a module once, keep members namespaced, configure !default values when needed, and leave LibSass-era @import behind on Dart Sass 1.23+.

Continue with @forward or browse math.abs().

Next: Sass @forward Rule

Re-export modules from one entrypoint with prefixes, show/hide, and configuration.

@forward rule →

About the author

Mari Selvan M P
Mari Selvan M P 🔗

Developer, cloud engineer, and technical writer

  • Experience 12 years building web and cloud systems
  • Focus Full Stack Development, AWS, and Developer Education

I write practical tutorials so students and working developers can learn by doing—from databases and APIs to deployment on AWS.

5 people found this page helpful