The <code>@forward</code> directive lets you re-export styles, variables, and mixins from one Sass file to another, making them available to files that import the forwarding file.
Click to reveal answer
intermediate
How is @forward different from @import in Sass?
@forward re-exports members for other files to use, while @import brings styles directly into the current file. @forward helps organize and control what is exposed to users.
Click to reveal answer
intermediate
How do you hide a variable or mixin when using @forward?
Use the hide keyword with @forward to prevent specific members from being re-exported, e.g., @forward 'colors' hide $secret-color;
Click to reveal answer
intermediate
What is the purpose of the as keyword in @forward?
The as keyword lets you rename members when forwarding, for example: @forward 'buttons' as btn-*; prefixes all forwarded members with btn-.
Click to reveal answer
beginner
Can you use @forward multiple times in one file?
Yes, you can use @forward multiple times to re-export members from different Sass files, helping you create a single entry point for many modules.
Click to reveal answer
What does @forward 'colors'; do in a Sass file?
ARe-exports all members from the 'colors' file for others to use
BImports styles from 'colors' directly into the current file
CDeletes the 'colors' file
DRenames the 'colors' file
✗ Incorrect
@forward re-exports members so other files importing this file can access them.
Which keyword hides members when using @forward?
Askip
Bexclude
Cremove
Dhide
✗ Incorrect
The hide keyword hides specific variables or mixins from being re-exported.
How do you rename forwarded members with @forward?
AUsing the <code>as</code> keyword
BUsing the <code>rename</code> keyword
CUsing the <code>change</code> keyword
DUsing the <code>to</code> keyword
✗ Incorrect
The as keyword adds a prefix or changes the name of forwarded members.
Can @forward replace @import in modern Sass projects?
ANo, <code>@import</code> is still required
BYes, <code>@forward</code> is part of the new module system replacing <code>@import</code>
CNo, they do completely different things
DYes, but only for CSS files
✗ Incorrect
@forward is used in the new module system to organize and share code, replacing @import.
What happens if you use @forward multiple times in one file?
AOnly the first <code>@forward</code> works
BIt causes an error
CYou can combine exports from many files into one
DIt duplicates styles in the output
✗ Incorrect
Multiple @forward directives let you create a single file that re-exports many modules.
Explain how the @forward directive helps organize Sass code in a project.
Think about how you share variables and mixins across files.
You got /4 concepts.
Describe how to hide and rename members when using @forward.
Consider how you might want to keep some things private or change names.
You got /3 concepts.
Practice
(1/5)
1. What is the main purpose of the @forward directive in Sass?
easy
A. To share styles from one Sass file to another without importing repeatedly
B. To import CSS files directly into Sass
C. To compile Sass files into CSS
D. To define variables inside a Sass file
Solution
Step 1: Understand the role of @forward
The @forward directive allows one Sass file to share its styles with another file, acting like a re-export.
Step 2: Compare with other options
Options B, C, and D describe different Sass features: importing CSS, compiling Sass, and defining variables, which are not the main purpose of @forward.
Final Answer:
To share styles from one Sass file to another without importing repeatedly -> Option A
Quick Check:
@forward shares styles = A [OK]
Hint: Remember: @forward re-exports styles, not imports or compiles [OK]
Common Mistakes:
Confusing @forward with @import
Thinking @forward compiles Sass
Assuming @forward defines variables
2. Which of the following is the correct syntax to forward a Sass file named _buttons.scss from _index.scss?
easy
A. @use "buttons";
B. @forward "_buttons.scss";
C. @forward "buttons";
D. @import "buttons";
Solution
Step 1: Identify correct syntax for @forward
The @forward directive uses the file name without underscore and extension, so @forward "buttons"; is correct.
Step 2: Eliminate other options
@forward "_buttons.scss"; incorrectly includes underscore and extension. @import "buttons"; uses @import, and @use "buttons"; uses @use, both different directives.
Final Answer:
@forward "buttons"; -> Option C
Quick Check:
Forward syntax excludes underscore and extension = D [OK]
Hint: Use file name without underscore or extension in @forward [OK]
Common Mistakes:
Including underscore or .scss extension in @forward