The @use directive imports another Sass file and makes its variables, mixins, and functions available under a namespace.
Click to reveal answer
beginner
How do you access a variable named $color from a file imported with @use 'colors';?
You access it with the namespace like this: colors.$color.
Click to reveal answer
intermediate
Why is @use preferred over @import in modern Sass?
@use avoids variable and mixin conflicts by using namespaces and loads files only once, improving clarity and performance.
Click to reveal answer
intermediate
How can you rename a namespace when using @use?
You can rename it with the as keyword, for example: @use 'colors' as c; then access variables like c.$color.
Click to reveal answer
intermediate
What happens if you use @use multiple times for the same file?
Sass loads the file only once, so multiple @use statements for the same file share the same namespace and do not duplicate code.
Click to reveal answer
What is the main benefit of using @use instead of @import in Sass?
AIt imports CSS files only
BIt creates a namespace to avoid conflicts
CIt allows inline styles
DIt disables variables
✗ Incorrect
@use creates a namespace so variables and mixins don’t clash, unlike @import.
How do you access a mixin named button from a file imported as @use 'styles' as s;?
Abutton()
Bs.button()
C@include s.button;
D@include button;
✗ Incorrect
You use @include with the namespace: @include s.button;.
Which keyword lets you rename the namespace when using @use?
Arename
Bnamespace
Cwith
Das
✗ Incorrect
The as keyword renames the namespace, e.g., @use 'file' as f;.
If you want to use variables from a file without a namespace, what can you do?
AUse <code>@use 'file' as *;</code>
BUse <code>@import 'file';</code>
CUse <code>@use 'file' no-namespace;</code>
DUse <code>@use 'file' global;</code>
✗ Incorrect
@use 'file' as *; imports all members without a namespace, but it’s less safe.
What happens if you try to import the same file twice with @use?
AThe file is loaded once and shared
BAn error occurs
CThe second import is ignored silently
DThe file is loaded twice
✗ Incorrect
@use loads the file once and shares the namespace to avoid duplication.
Explain how the @use directive works in Sass and why it is better than @import.
Think about how variables and mixins are accessed and how duplication is prevented.
You got /5 concepts.
Describe how to rename a namespace when importing a file with @use and how to access a variable from it.
Remember the pattern: namespace.variable
You got /3 concepts.
Practice
(1/5)
1. What is the main purpose of the @use directive in Sass?
easy
A. To import Sass files with a namespace to avoid conflicts
B. To directly copy CSS styles without any namespace
C. To run JavaScript code inside Sass files
D. To export variables from Sass files
Solution
Step 1: Understand the role of @use
The @use directive imports Sass files and applies a namespace to their contents.
Step 2: Compare with other import methods
Unlike @import, @use avoids naming conflicts by requiring namespace prefixes.
Final Answer:
To import Sass files with a namespace to avoid conflicts -> Option A
Quick Check:
@use adds namespace = C [OK]
Hint: Remember: @use always adds a namespace [OK]
Common Mistakes:
Thinking @use copies styles without namespace
Confusing @use with JavaScript execution
Believing @use exports variables
2. Which of the following is the correct syntax to import a Sass file named colors.scss using @use?
easy
A. @use 'colors';
B. @use colors.scss;
C. @use "colors.scss";
D. @use colors;
Solution
Step 1: Check correct quoting and file extension
The @use directive requires the file path as a string without the extension, usually quoted.
Step 2: Validate options
@use 'colors'; uses quotes and omits the extension, which is correct. Options B and C include the extension incorrectly or wrong quotes. @use colors; lacks quotes.
Final Answer:
@use 'colors'; -> Option A
Quick Check:
Quotes + no extension = D [OK]
Hint: Use quotes and omit .scss extension in @use [OK]
Common Mistakes:
Including the .scss extension inside @use
Not using quotes around the file name
Using double quotes inconsistently
3. Given the following Sass files, what will be the color of the h1 text?
@use 'colors';
h1 {
color: colors.$primary;
}
// colors.scss
$primary: blue;
$secondary: green;
medium
A. green
B. black
C. red
D. blue
Solution
Step 1: Identify the imported variables
The @use 'colors'; imports variables with the namespace colors. The variable $primary is set to blue.
Step 2: Check the usage in h1
The color is set to colors.$primary, which refers to blue.
C. Variables must be accessed with namespace prefix unless configured
D. Variables cannot be used inside selectors
Solution
Step 1: Understand @use namespace behavior
By default, variables must be accessed with the namespace prefix unless as * is used to remove it.
Step 2: Check the code usage
The code uses @use 'theme'; without as *, so variables must be accessed with the theme. prefix, but $main-color is used without it, causing an undefined variable error.
Step 3: Identify the actual problem
Without as *, the prefix is required, so Variables must be accessed with namespace prefix unless configured identifies the issue.
Final Answer:
Variables must be accessed with namespace prefix unless configured -> Option C
Quick Check:
Default namespace prefix required = A [OK]
Hint: Use namespace or as * to access variables directly [OK]
Common Mistakes:
Thinking as * is invalid syntax
Forgetting to prefix variables without as *
Including .scss extension in @use
5. You want to import variables.scss but rename its namespace to vars and override the variable $font-size to 1.5rem. Which @use syntax is correct?
hard
A. @use 'variables' as vars ($font-size: 1.5rem);
B. @use 'variables' as vars with ($font-size: 1.5rem);
C. @use 'variables' with ($font-size: 1.5rem) as vars;
D. @use 'variables' rename vars with ($font-size: 1.5rem);
Solution
Step 1: Recall @use syntax for renaming and configuring
The correct syntax is @use 'file' as namespace with (variable overrides);.
Step 2: Match options to syntax
@use 'variables' as vars with ($font-size: 1.5rem); matches the correct order and syntax. Options B, C, and D have incorrect order or keywords.
Final Answer:
@use 'variables' as vars with ($font-size: 1.5rem); -> Option B
Quick Check:
Namespace + with (overrides) = A [OK]
Hint: Use as then with for renaming and overrides [OK]
Common Mistakes:
Swapping as and with order
Using invalid keywords like rename
Omitting parentheses around overrides
Recommended
Ready to prove it?
Pass the test and this pattern moves unknownstrongwhile earning +1 Grip toward your certificate.