Bird
Raised Fist0
SASSmarkup~20 mins

Combining & with BEM naming in SASS - Practice Problems & Coding Challenges

Choose your learning style10 modes available
Challenge - 5 Problems
🎖️
BEM & Sass Mastery
Get all challenges correct to earn this badge!
Test your skills under time pressure!
❓ selector
intermediate
2:00remaining
What CSS selector does this Sass code produce?
Given the Sass code below, what is the final CSS selector generated for the .block__element--modifier style?
SASS
.block {
  &__element {
    &--modifier {
      color: red;
    }
  }
}
A.block__element--modifier { color: blue; }
B.block .__element--modifier { color: red; }
C.block__element .--modifier { color: red; }
D.block__element--modifier { color: red; }
Attempts:
2 left
💡 Hint
Remember that & replaces the parent selector exactly where it appears.
📝 Syntax
intermediate
2:00remaining
Which option causes a syntax error in Sass when combining & with BEM naming?
Identify which Sass snippet below will cause a syntax error due to incorrect use of & with BEM naming.
A
.block {
  &--modifier
    color: green;
  }
B
.block {
  &__element--modifier {
    color: red;
  }
}
C
.block {
  &__element {
    color: blue;
  }
}
D
.block {
  &__element--modifier {
    &--extra {
      color: yellow;
    }
  }
}
Attempts:
2 left
💡 Hint
Check for missing opening braces `{` after nested selectors.
❓ selector
intermediate
2:00remaining
Which Sass code produces a descendant selector instead of BEM concatenated class?
Choose the Sass code that compiles to a descendant selector `.block __element` instead of the proper BEM concatenated `.block__element`.
A
.block {
  & __element {
    color: yellow;
  }
}
B
.block {
  &--modifier {
    color: green;
  }
}
C
.block {
  &__element {
    color: blue;
  }
}
D
.block {
  &__element--modifier {
    color: red;
  }
}
Attempts:
2 left
💡 Hint
A space after & inserts a descendant combinator (space), preventing concatenation for BEM class names.
❓ rendering
advanced
2:00remaining
What color will the element with class block__element--modifier have?
Given the Sass code below, what color will the element with class block__element--modifier display in the browser?
SASS
.block {
  &__element {
    color: blue;
    &--modifier {
      color: red;
    }
  }
}
ABlue
BNo color applied
CRed
DPurple
Attempts:
2 left
💡 Hint
Look at the nested selectors and which color applies to the modifier class.
❓ accessibility
expert
3:00remaining
How to improve accessibility when using BEM modifiers with & in Sass?
You have a button styled with BEM naming and Sass using & for modifiers. Which practice improves accessibility the most?
AUse only BEM modifiers with & in Sass to change colors for visual states.
BAdd ARIA roles and states to the button element in HTML, not just rely on CSS classes.
CAdd tabindex="-1" to all modifier classes to prevent keyboard focus.
DUse !important in Sass modifiers to ensure styles override defaults.
Attempts:
2 left
💡 Hint
Think about what helps screen readers and keyboard users, not just visual styles.

Practice

(1/5)
1. What does the & symbol represent when used in Sass with BEM naming?
easy
A. It resets all styles inside the block.
B. It creates a new CSS class unrelated to the parent.
C. It imports external CSS files.
D. It refers to the current parent selector in the nested block.

Solution

  1. Step 1: Understand the role of & in Sass

    The & symbol in Sass means "use the current parent selector" inside nested rules.
  2. Step 2: Connect with BEM naming

    When combined with BEM, &__element or &--modifier appends to the parent block's class name.
  3. Final Answer:

    It refers to the current parent selector in the nested block. -> Option D
  4. Quick Check:

    & = current parent selector [OK]
Hint: Remember & means "this block" in nested Sass [OK]
Common Mistakes:
  • Thinking & creates a new unrelated class
  • Confusing & with a CSS variable
  • Using & to import files
2. Which of the following Sass snippets correctly uses & to create a BEM modifier for a block named .card?
easy
A. &__active { background: green; }
B. .card--active { background: green; }
C. &--active { background: green; }
D. &-active { background: green; }

Solution

  1. Step 1: Identify BEM modifier syntax

    Modifiers use double dashes: --modifier, so &--active appends --active to the parent block.
  2. Step 2: Check other options

    .card--active { background: green; } repeats the full class, not using &. &__active { background: green; } uses __ which is for elements, not modifiers. &-active { background: green; } uses a single dash, which is incorrect for BEM modifiers.
  3. Final Answer:

    &--active { background: green; } -> Option C
  4. Quick Check:

    Modifier = &--modifier [OK]
Hint: Use &--modifier for modifiers inside blocks [OK]
Common Mistakes:
  • Using single dash instead of double dash for modifiers
  • Confusing elements (__element) with modifiers (--modifier)
  • Writing full class name instead of using &
3. Given the Sass code below, what CSS will it generate?
.button {
  color: blue;
  &__icon {
    margin-right: 0.5rem;
  }
  &--large {
    font-size: 2rem;
  }
}
medium
A. .button { color: blue; } &__icon { margin-right: 0.5rem; } &--large { font-size: 2rem; }
B. .button { color: blue; } .button__icon { margin-right: 0.5rem; } .button--large { font-size: 2rem; }
C. .button { color: blue; } .icon { margin-right: 0.5rem; } .large { font-size: 2rem; }
D. .button { color: blue; } .button_icon { margin-right: 0.5rem; } .button_large { font-size: 2rem; }

Solution

  1. Step 1: Understand & usage in nested selectors

    The & appends to the parent selector .button. So &__icon becomes .button__icon and &--large becomes .button--large.
  2. Step 2: Write the generated CSS

    The CSS will have three selectors: .button, .button__icon, and .button--large with their respective styles.
  3. Final Answer:

    .button { color: blue; } .button__icon { margin-right: 0.5rem; } .button--large { font-size: 2rem; } -> Option B
  4. Quick Check:

    & + BEM = combined class names [OK]
Hint: &__element and &--modifier append to block class [OK]
Common Mistakes:
  • Using underscore instead of double underscore for elements
  • Not combining & with parent selector
  • Leaving & in final CSS
4. Identify the error in this Sass code using BEM naming:
.menu {
  &__item {
    color: black;
  }
  &-active {
    font-weight: bold;
  }
}
medium
A. The modifier should use double dashes: &--active instead of &-active.
B. The element selector &__item is invalid and should be &-item.
C. The parent selector .menu is missing a dot.
D. The color property cannot be inside &__item.

Solution

  1. Step 1: Check BEM modifier syntax

    Modifiers in BEM use double dashes --, so &-active is incorrect; it should be &--active.
  2. Step 2: Verify element syntax

    &__item is correct for elements, so no error there.
  3. Final Answer:

    The modifier should use double dashes: &--active instead of &-active. -> Option A
  4. Quick Check:

    Modifier syntax = &--modifier [OK]
Hint: Modifiers always use double dashes -- not single [OK]
Common Mistakes:
  • Using single dash for modifiers
  • Confusing element and modifier syntax
  • Thinking &__item is invalid
5. You want to style a BEM block .profile with an element avatar and a modifier highlighted. Which Sass code correctly combines & with BEM naming to style both the element and modifier inside .profile?
hard
A. .profile { &__avatar { border-radius: 50%; } &--highlighted { background-color: yellow; } }
B. .profile { &-avatar { border-radius: 50%; } &-highlighted { background-color: yellow; } }
C. .profile { &__avatar { border-radius: 50%; } &-highlighted { background-color: yellow; } }
D. .profile { &-avatar { border-radius: 50%; } &--highlighted { background-color: yellow; } }

Solution

  1. Step 1: Apply BEM element syntax

    Elements use double underscore __, so &__avatar correctly targets .profile__avatar.
  2. Step 2: Apply BEM modifier syntax

    Modifiers use double dash --, so &--highlighted correctly targets .profile--highlighted.
  3. Step 3: Check other options

    Options A, C, and D use single dash for either element or modifier, which is incorrect in BEM.
  4. Final Answer:

    .profile { &__avatar { border-radius: 50%; } &--highlighted { background-color: yellow; } } -> Option A
  5. Quick Check:

    Element = &__element, Modifier = &--modifier [OK]
Hint: Use &__element and &--modifier exactly for BEM [OK]
Common Mistakes:
  • Using single dash for elements or modifiers
  • Mixing element and modifier syntax
  • Not nesting inside the block selector
Recommended

Ready to prove it?

Pass the test and this pattern moves unknown strong while earning +1 Grip toward your certificate.

10 questions~5 mineasy hard