Chepter 6: Sass @import

Sass @import and Partials in detail, like we’re refactoring an old project together right now.

This topic is super important because the rules changed dramatically in recent years, and in February 2026 we’re in a transition phase. I’ll explain both the old world (@import) and the new recommended world (@use + partials), why the change happened, and how to actually organize your files today.

1. What Are Partials in Sass? (This part never changed)

Partials are Sass files that are not meant to be compiled into CSS by themselves. They contain variables, mixins, functions, base styles, etc., that other files will load.

Convention (still 100% used in 2026):

  • File name starts with underscore _ Example: _variables.scss, _mixins.scss, _reset.scss, _buttons.scss

  • When you load them, you can omit the underscore and .scss extension:

    Old way: @import ‘variables’; New way: @use ‘variables’;

Why the _? Sass tools (VS Code Live Sass Compiler, webpack, Vite, Parcel, etc.) see the _ and skip compiling that file to CSS. No _variables.css junk file gets created.

2. The Old Way: @import (Still Works, But Deprecated)

How it worked (and still technically works in Dart Sass until ~2028+):

SCSS

What @import did:

  • Copies everything from the imported file into this one (variables, mixins, CSS rules)
  • Puts them in the global namespace — everything is shared and can clash
  • Loads the file every time it’s referenced (but Sass dedupes CSS output)
  • Can be nested inside rules (e.g. inside media queries — rare but possible)
  • Very simple syntax

Big problems that accumulated over years:

  • Naming collisions (two partials define $spacing → chaos)
  • Hard to know where a variable/mixin came from
  • Circular imports easy to create accidentally
  • Global pollution → debugging nightmare in big teams/projects
  • No real modularity / encapsulation

Because of these, Sass team deprecated @import:

  • Official deprecation started in Dart Sass 1.80.0 (October 2024)
  • Warnings appear in console now
  • Will be completely removed in Dart Sass 3.0.0 (planned no sooner than ~late 2026 / 2027, at least 2 years after deprecation)

So in 2026: You still see @import in old projects, Bootstrap 5, many tutorials… but new code should avoid it.

3. The Modern Way: @use + Partials (Recommended in 2026)

@use is the new module system (introduced 2019, mature by 2026).

Key differences from @import:

  • Loads file as a module
  • Variables, functions, mixins are scoped to the file that uses them (no global pollution by default)
  • You must access them with namespace (or use as * to dump into local scope)
  • CSS rules are included only once (even if used multiple times)
  • @usemust be at top level (cannot nest inside selectors/media queries)
  • Encourages clean, predictable code

Basic example – folder structure (modern 2026 best practice)

text

_variables.scss (partial)

SCSS

_mixins.scss

SCSS

main.scss (entry point – this gets compiled)

SCSS

Alternative – if you hate typing namespace every time:

SCSS

Caution: as * is convenient but reduces traceability — use sparingly (good for base variables/mixins, avoid in large teams).

4. @forward – The Missing Piece for Barrel/Index Files

You often want an index file to collect many partials:

Create scss/base/_index.scss:

SCSS

Then in main.scss:

SCSS

This is super clean for large projects — one @use brings in many things.

5. Quick Comparison Table (2026 Perspective)

Feature @import (old) @use (modern) Winner
Namespace / scoping Global everything Scoped by default + namespace @use
Can nest inside rules? Yes No (top-level only) @import (but rarely needed)
Deprecation status Deprecated since 1.80.0 Recommended forever @use
Duplicate CSS output Deduped Explicitly included only once @use
Traceability (where from?) Hard Easy (namespace or file name) @use
Future-proof Will break in Dart Sass 3.0 The future @use

6. Migration Tip (If You Have Old Code)

  1. Start new files with @use
  2. For old projects: install Sass migrator tool
    Bash

    It auto-converts @import → @use in many cases

  3. Suppress warnings temporarily if stuck: –quiet-deps flag in Sass command

You’ve now got the full picture: Partials = _name.scss files Old glue = @import (avoid new code) New glue = @use + optionally @forward for clean architecture

Next class — want to build a full modular folder structure example with variables + mixins + buttons + cards? Or explain @forward deeper with index files? Or how to handle global resets / fonts in modern Sass?

Just say — we’re making progress fast! 🚀

You may also like...

Leave a Reply

Your email address will not be published. Required fields are marked *