In Sass, the $ symbol is used to declare a variable. It helps store values like colors, sizes, or fonts that you can reuse throughout your stylesheet.
Click to reveal answer
beginner
How do you declare a variable named $main-color with the value #3498db in Sass?
You write:
$main-color: #3498db;
This sets $main-color to a blue color you can use later.
Click to reveal answer
beginner
Why use variables in Sass instead of repeating values?
Variables make your code easier to update and maintain. Change the value once, and it updates everywhere the variable is used, saving time and reducing mistakes.
Click to reveal answer
intermediate
Can you change the value of a Sass variable after it is declared?
Yes, Sass variables can be reassigned later in the same scope, and the new value will be used in subsequent rules.
Click to reveal answer
beginner
How do you use a Sass variable inside a CSS rule?
Use the variable by writing its name with $. For example:
color: $main-color;
This applies the stored color value.
Click to reveal answer
What symbol starts a variable name in Sass?
A%
B#
C@
D$
✗ Incorrect
In Sass, variables always start with the $ symbol.
Which of these is a correct Sass variable declaration?
A$font-size: 16px;
Bfont-size = 16px;
C@font-size: 16px;
Dfont-size: $16px;
✗ Incorrect
Sass variables are declared with $name: value; syntax.
If you want to change a color used many times, what is the best Sass practice?
AChange each color manually
BUse a variable and change its value once
CUse inline styles
DUse !important everywhere
✗ Incorrect
Using variables lets you update the color in one place, which updates all uses.
Can you reassign a Sass variable after it is set?
AYes, anytime
BOnly if you use !default
COnly inside media queries
DNo, variables are immutable
✗ Incorrect
Sass variables can be reassigned after they are declared.
How do you apply a Sass variable $main-color to a CSS property?
Acolor: main-color;
Bcolor: #main-color;
Ccolor: $main-color;
Dcolor: var(main-color);
✗ Incorrect
Use the variable name with $ directly in the property value.
Explain how to declare and use a variable in Sass with an example.
Think about how you store a color once and use it multiple times.
You got /4 concepts.
Why are variables helpful in Sass? Describe a real-life situation where they save time.
Imagine changing a color on a website with many pages.
You got /4 concepts.
Practice
(1/5)
1. What symbol is used to declare a variable in Sass?
easy
A. $
B. #
C. @
D. %
Solution
Step 1: Recall Sass variable syntax
In Sass, variables always start with the $ symbol to distinguish them from other values.
Step 2: Identify the correct symbol
Among the options, only $ is used for variables in Sass.
Final Answer:
$ -> Option A
Quick Check:
Variables start with $ in Sass [OK]
Hint: Remember: Sass variables always begin with $ [OK]
Common Mistakes:
Using # or @ instead of $ for variables
Confusing CSS IDs (#) with Sass variables
Omitting the $ symbol before variable names
2. Which of the following is the correct way to declare a color variable in Sass?
easy
A. main-color: $3498db;
B. $main-color: #3498db;
C. $main-color = #3498db;
D. @main-color: #3498db;
Solution
Step 1: Check variable declaration syntax
Sass variables start with $, followed by the name, a colon, then the value, ending with a semicolon.
Step 2: Compare options
$main-color: #3498db; matches the correct syntax: $main-color: #3498db;. Others use wrong symbols or order.
Final Answer:
$main-color: #3498db; -> Option B
Quick Check:
Variable declaration uses $name: value; [OK]
Hint: Use $name: value; to declare variables in Sass [OK]
Common Mistakes:
Using = instead of : to assign values
Placing $ after the variable name
Using @ instead of $ for variables
3. What will be the background color of the button in this Sass code?