The @use rule loads another Sass file and makes its variables, mixins, and functions available with a namespace to avoid name conflicts.
Click to reveal answer
beginner
How do you change the namespace when using @use in Sass?
You can change the namespace by adding as newName after the file path, like @use 'colors' as c; which lets you access items with c.$variable.
Click to reveal answer
beginner
Why is namespace control important in Sass?
Namespace control helps avoid naming conflicts when multiple Sass files have variables or mixins with the same name, keeping styles organized and clear.
Click to reveal answer
intermediate
What happens if you use @use 'file' as *; in Sass?
Using as * imports all members without a namespace, making variables and mixins available directly but risking name conflicts.
Click to reveal answer
beginner
Show an example of using @use with a custom namespace.
Example:
@use 'colors' as c;
.button {
color: c.$primary-color;
}
This uses c as the namespace for the colors file.
Click to reveal answer
What does @use 'variables' as v; do in Sass?
ALoads variables with the namespace 'v'
BLoads variables without any namespace
CImports variables as global variables
DRemoves the variables file
✗ Incorrect
The @use rule with as v loads the file with the namespace 'v', so you access variables like v.$variable-name.
Which of these is a risk when using @use 'file' as *;?
AName conflicts between variables
BFile not found error
CSlower compilation
DVariables become private
✗ Incorrect
Using as * imports all members without a namespace, which can cause name conflicts if different files have the same variable names.
Why prefer @use over @import in Sass?
AThey are exactly the same
B<code>@import</code> is faster
C<code>@use</code> supports namespaces and avoids conflicts
D<code>@use</code> is deprecated
✗ Incorrect
@use creates namespaces and avoids variable conflicts, while @import can cause conflicts and is deprecated.
How do you access a variable named $color from a file loaded as @use 'theme' as t;?
A$color
Bt.$color
Ctheme.$color
Dcolor
✗ Incorrect
When loaded with namespace t, you access variables as t.$color.
What is the default namespace when using @use 'file'; without as?
AThe word 'use'
BNo namespace
CGlobal namespace
DThe file name
✗ Incorrect
By default, the namespace is the file name, so you access members with fileName.$variable.
Explain how namespace control works with @use as in Sass and why it is useful.
Think about how you keep things organized when you have many files with similar names.
You got /4 concepts.
Describe the difference between using @use 'file' as namespace; and @use 'file' as *; in Sass.
Consider how you call variables after importing.
You got /3 concepts.
Practice
(1/5)
1. What does the @use 'colors' as c; statement do in Sass?
easy
A. It imports the 'colors' file and merges all variables globally.
B. It imports the 'colors' file and renames its namespace to 'c'.
C. It imports the 'colors' file without any namespace.
D. It imports the 'colors' file and disables all variables.
Solution
Step 1: Understand the @use rule
The @use rule imports a Sass file and creates a namespace for its variables and mixins.
Step 2: Analyze the as c part
The as c renames the namespace from the default (usually the filename) to c.
Final Answer:
It imports the 'colors' file and renames its namespace to 'c'. -> Option B
Quick Check:
@use with as renames namespace [OK]
Hint: Remember: @use 'file' as alias; renames namespace [OK]
Common Mistakes:
Thinking @use removes the namespace
Confusing @use with @import
Assuming variables become global without namespace
2. Which of the following is the correct syntax to import a Sass file buttons.scss with namespace btn?
easy
A. @use buttons as btn;
B. @use 'buttons.scss' btn;
C. @use 'buttons' as btn;
D. @use 'buttons' btn;
Solution
Step 1: Check the @use syntax
The correct syntax requires quotes around the filename and the keyword as before the alias.
Step 2: Validate each option
@use 'buttons' as btn; uses quotes and as correctly. Options A, C, and D miss quotes or the as keyword.
Final Answer:
@use 'buttons' as btn; -> Option C
Quick Check:
Quotes + as keyword = correct syntax [OK]
Hint: Always use quotes and 'as' for alias in @use [OK]
Common Mistakes:
Omitting quotes around filename
Forgetting the 'as' keyword
Adding file extension inside quotes unnecessarily
3. Given @use 'theme/colors' as c; and the file colors.scss contains $primary: #0055ff;, what is the correct way to use $primary in your styles?
medium
A. color: c.$primary;
B. color: $primary;
C. color: colors.$primary;
D. color: theme.colors.$primary;
Solution
Step 1: Understand namespace usage
When using @use 'file' as alias;, variables must be accessed with alias.variable.
Step 2: Apply alias to variable
Since the alias is c, the variable $primary is accessed as c.$primary.
Final Answer:
color: c.$primary; -> Option A
Quick Check:
Use alias.variable to access imported variables [OK]
Hint: Use alias.variable to access imported Sass variables [OK]
Common Mistakes:
Using variable without alias
Using original filename as namespace instead of alias
Trying to chain namespaces incorrectly
4. What is wrong with this Sass code?
@use 'utils' as u;
.button { color: $main-color; }
medium
A. Variable $main-color is used without namespace prefix.
B. Missing semicolon after @use statement.
C. The alias 'u' cannot be a single letter.
D. The file 'utils' cannot be used with @use.
Solution
Step 1: Verify the @use syntax
The @use 'utils' as u; statement correctly imports the file with namespace u.
Step 2: Check variable usage
Since @use 'utils' as u; creates a namespace u, variables inside must be accessed as u.$main-color. Using $main-color alone causes an error.
Final Answer:
Variable $main-color is used without namespace prefix. -> Option A
Quick Check:
Variables need namespace prefix after @use [OK]
Hint: Always prefix variables with alias after @use [OK]
Common Mistakes:
Forgetting to prefix variables with alias
Assuming @use imports variables globally
Thinking alias must be longer than one letter
5. You have two Sass files: colors.scss with $primary: #333; and buttons.scss with $primary: #555;. How do you import both files in main.scss using @use with aliases c and b to avoid naming conflicts and use both $primary variables?