The & symbol represents the parent selector. It lets you refer back to the current selector inside nested styles.
Click to reveal answer
beginner
How would you write a hover style for a button using the parent selector & in Sass?
You write it like this:
button { &:hover { color: red; } }
This means: when the button is hovered, change its color to red.
Click to reveal answer
intermediate
Can you use <code>&</code> to create a modifier class like <code>.btn-primary</code> inside <code>.btn</code>?
Yes! You can write:
.btn { &-primary { background: blue; } }
This creates a class .btn-primary with the styles inside.
Click to reveal answer
intermediate
What happens if you use & inside a nested selector like .menu > li?
The & will be replaced by the full parent selector. For example:
.menu { > li { color: green; } }
means .menu > li in CSS.
Click to reveal answer
beginner
Why is using & helpful in writing Sass?
It helps keep your code DRY (Don't Repeat Yourself). You can write nested styles that relate to the parent without repeating the full selector. It makes your code cleaner and easier to maintain.
Click to reveal answer
In Sass, what does &:hover inside a selector block do?
ATargets the hover state of the parent selector
BCreates a new unrelated selector
CTargets all child elements
DRemoves the parent selector
✗ Incorrect
&:hover means the hover state of the current parent selector.
How would you write a nested class .card-active inside .card using &?
A.card { &-active { ... } }
B.card { .active { ... } }
C.card-active { ... }
D.card { & .active { ... } }
✗ Incorrect
Using &-active appends '-active' to the parent selector .card.
What will this Sass code compile to?
.nav { > li { color: red; } }
A.nav li { color: red; }
Bli > .nav { color: red; }
C.nav > li { color: red; }
D.nav > .li { color: red; }
✗ Incorrect
The > li means direct child li of .nav.
Can & be used multiple times inside nested selectors?
AOnly if inside media queries
BNo, only once per block
COnly in the root selector
DYes, it always refers to the parent selector
✗ Incorrect
& can be used multiple times and always means the parent selector.
Which of these is a benefit of using & in Sass?
AAutomatically adds vendor prefixes
BAvoids repeating selectors and keeps code clean
CRemoves the need for classes
DMakes CSS slower to load
✗ Incorrect
& helps avoid repeating selectors and keeps your Sass code cleaner.
Explain how the parent selector & works in Sass and give an example of its use.
Think about how you write hover styles or modifier classes inside a main class.
You got /3 concepts.
Describe a situation where using & in Sass helps keep your code cleaner and easier to maintain.
Consider writing styles for buttons with hover and active states.
You got /3 concepts.
Practice
(1/5)
1. What does the & symbol represent in Sass when used inside nested selectors?
easy
A. It resets all styles to default.
B. It creates a new global selector.
C. It refers to the current parent selector.
D. It comments out the nested block.
Solution
Step 1: Understand the role of & in Sass nesting
The & symbol is used to refer back to the parent selector in nested Sass code.
Step 2: Identify what & does in the context
It helps avoid repeating the parent selector by representing it directly.
Final Answer:
It refers to the current parent selector. -> Option C
Quick Check:
& means parent selector [OK]
Hint: Remember & means "this parent" selector in Sass [OK]
Common Mistakes:
Thinking & creates a new selector
Confusing & with a comment symbol
Assuming & resets styles
2. Which of the following is the correct Sass syntax to style a button with a hover effect using the parent selector &?
easy
A. button {
&hover {
color: red;
}
}
B. button {
& :hover {
color: red;
}
}
C. button {
&:hover() {
color: red;
}
}
D. button {
&:hover {
color: red;
}
}
Solution
Step 1: Check the correct pseudo-class syntax with &
The correct way to use & with a pseudo-class is &:hover without spaces or parentheses.
& .title is valid for child selector, &.highlight is valid for combined class.
Step 2: Identify incorrect pseudo-class syntax
&hover is missing the colon and should be &:hover.
Final Answer:
Missing colon in &:hover pseudo-class -> Option A
Quick Check:
Pseudo-classes need colon after & [OK]
Hint: Pseudo-classes need &: not & alone [OK]
Common Mistakes:
Forgetting colon before pseudo-class
Thinking space after & is always wrong
Assuming & can't combine with classes
5. You want to style a list where the li elements inside a ul have a special style only when the ul has a class highlight. Which Sass code using & correctly achieves this?
hard
A. ul.highlight {
li & {
color: green;
}
}
B. ul {
&.highlight li {
color: green;
}
}
C. ul {
li {
&.highlight {
color: green;
}
}
}
D. ul {
& li.highlight {
color: green;
}
}
Solution
Step 1: Understand the selector goal
We want to style li inside ul.highlight, so the selector is ul.highlight li.
Step 2: Check which Sass code produces that selector
ul {
&.highlight li {
color: green;
}
} nests &.highlight li inside ul, so & becomes ul, resulting in ul.highlight li.
Final Answer:
ul { &.highlight li { color: green; } } -> Option B
Quick Check:
& replaces parent selector exactly where placed [OK]
Hint: Place & where parent selector should appear in nested code [OK]
Common Mistakes:
Misplacing & causing wrong selector order
Trying to put & inside child selector
Confusing class placement on li instead of ul
Recommended
Ready to prove it?
Pass the test and this pattern moves unknownstrongwhile earning +1 Grip toward your certificate.