Using @use lets you bring in built-in Sass modules to use their features. It helps keep your styles organized and easy to manage.
Importing built-in modules with @use in SASS
@use "sass:module-name";
Replace module-name with the built-in module you want, like color or math.
The @use rule loads the module once and gives it a namespace to avoid conflicts.
color module so you can use its color functions.@use "sass:color";
math module to use math functions like math.round().@use "sass:math";
list module to work with lists in Sass.@use "sass:list";
This Sass code imports the built-in color and math modules. It lightens a base blue color by 20% for the button background. It also rounds the padding value for neat spacing.
@use "sass:color"; @use "sass:math"; $base-color: #3498db; .button { background-color: color.scale($base-color, $lightness: 20%); padding: math.round(1.5)rem 2rem; color: white; border-radius: 0.5rem; }
Always use the @use rule at the top of your Sass file before other styles.
Built-in modules come with Sass, so you don't need to install anything extra.
Using namespaces like color. or math. helps avoid confusion with your own variables or functions.
@use imports built-in Sass modules to access their features.
It helps keep your styles organized and avoids naming conflicts.
Use the syntax @use "sass:module-name"; to import modules like color or math.
Practice
@use rule do when importing built-in modules?Solution
Step 1: Understand the purpose of
The@use@userule imports Sass modules and gives access to their functions and variables under a namespace.Step 2: Differentiate from other Sass features
Unlike@import,@usedoes not import raw CSS but Sass modules with scoped namespaces.Final Answer:
It imports a built-in Sass module to use its features with a namespace. -> Option BQuick Check:
@useimports modules with namespace [OK]
- Confusing @use with @import for CSS files
- Thinking @use compiles Sass to CSS
- Assuming @use removes unused CSS
math module using @use?Solution
Step 1: Recall the correct syntax for built-in modules
Built-in Sass modules are imported with@use "sass:module-name";syntax.Step 2: Check each option
@use "sass:math"; uses the correct syntax with quotes and the prefixsass:. Others miss quotes, prefix, or use@import.Final Answer:
@use "sass:math"; -> Option CQuick Check:
Built-in modules need@use "sass:module";[OK]
- Omitting quotes around module name
- Using @import instead of @use
- Forgetting the "sass:" prefix
@use "sass:color";
.my-text {
color: color.scale(color.$blue, $lightness: 20%);
}What color effect does this code apply to
.my-text?Solution
Step 1: Understand
Thecolor.scalefunctioncolor.scalefunction adjusts color properties like lightness by the given percentage.Step 2: Analyze the argument
This increases the lightness of the blue color by 20%, making it lighter.$lightness: 20%Final Answer:
It makes the blue color 20% lighter. -> Option DQuick Check:
color.scalewith positive lightness increases brightness [OK]
- Confusing lightness increase with darkening
- Assuming color changes hue instead
- Thinking the code has syntax errors
@use "sass:math";
.box {
width: math.percentage(0.5);
}Solution
Step 1: Check the function name in the math module
The correct function to convert a decimal to a percentage ismath.percent(), notmath.percentage().Step 2: Verify the rest of the code
The@usestatement is correct and has a semicolon; only the function name is wrong.Final Answer:
Themath.percentage()function does not exist; it should bemath.percent(). -> Option AQuick Check:
Usemath.percent()for percentage conversion [OK]
- Using incorrect function name math.percentage()
- Thinking @use needs no semicolon
- Assuming code is error-free
math module to calculate the width as 75% of 1200px. Which code correctly imports the module and calculates the width?Solution
Step 1: Import the math module correctly
The code uses@use "sass:math";which is correct for built-in modules.Step 2: Calculate 75% of 1200px correctly
Usingmath.div(75, 100)divides 75 by 100 to get 0.75, then multiplies by 1200px for the width.Step 3: Check other options for errors
@use "sass:math"; .container { width: math.percent(0.75); } sets width to 75% of the parent, not a fixed 900px. @use "sass:math"; .container { width: math.div(75%, 100) * 1200px; } usesmath.div(75%, 100)which equals 0.75% (dividing percentage by unitless keeps %), so 0.75% * 1200px = 9px. @use "sass:math"; .container { width: math.percent(75) * 1200px; } usesmath.percent(75)which returns 7500%.Final Answer:
@use "sass:math"; .container { width: math.div(75, 100) * 1200px; } -> Option AQuick Check:
Use math.div for division, multiply for percentage calculation [OK]
- Using math.percent() for relative percentage instead of fixed pixel calculation
- Dividing percentages by unitless numbers (keeping % unit)
- Misunderstanding multiplication with units
Ready to prove it?
Pass the test and this pattern moves unknown
