iwantcoding.com
🔥 Daily 👥 Rooms 🏆 Top Log in Sign up

Partials & @use

Partials are Sass files starting with an underscore (_buttons.scss). They aren't compiled to standalone CSS; you load them with @@use into your main stylesheet. Partials are how you organise a large codebase.

Partials + @@use + namespacing

EXAMPLE
// src/_tokens.scss — partial, not compiled standalone
$brand: #04AA6D;
$radius: 6px;

@mixin focus-ring($colour: $brand) {
    outline: 2px solid $colour;
    outline-offset: 2px;
}

// src/_buttons.scss
@use 'tokens' as t;       // namespace alias

.btn {
    padding: 8px 16px;
    border-radius: t.$radius;
    background: t.$brand;
    &:focus-visible { @include t.focus-ring; }
}

// src/main.scss — the only file compiled to CSS
@use 'tokens';
@use 'buttons';
@use 'cards';
@use 'forms';

body { background: tokens.$brand; }

// Compile
sass src/main.scss dist/main.css

// @use is namespaced and only loads each file ONCE.
// (The old @import is deprecated — it polluted the global namespace and re-loaded files.)

Why it matters

One main.scss per stylesheet bundle. _*.scss partials underneath. Namespaces (@use 'tokens' as t) keep collisions impossible across a big project.

Tip: Tweak the snippet with Try it Yourself », then sit the quiz at the bottom of the page.

Example

Example
// _vars.scss
$brand: #04AA6D;
// main.scss
@use 'vars';
button { background: vars.$brand; }
Try it Yourself »

Exercise

A partial filename is…

buttons.scss

Test yourself

Q1. A partial filename starts with…
Q2. The modern way to include a partial is…
Q3. @use namespaces members behind…

Discussion

Loading…