Bird
Raised Fist0
SASSmarkup~20 mins

Content blocks with @content in SASS - Practice Problems & Coding Challenges

Choose your learning style10 modes available
Challenge - 5 Problems
🎖️
Sass Content Block Master
Get all challenges correct to earn this badge!
Test your skills under time pressure!
📝 Syntax
intermediate
2:00remaining
What is the output CSS of this Sass code using @content?
Consider the following Sass code. What CSS does it produce when compiled?
@mixin card() {
  border: 1px solid #ccc;
  padding: 1rem;
  @content;
  background: white;
}

.container {
  @include card() {
    box-shadow: 0 0 5px rgba(0,0,0,0.1);
  }
}
SASS
@mixin card() {
  border: 1px solid #ccc;
  padding: 1rem;
  @content;
  background: white;
}

.container {
  @include card() {
    box-shadow: 0 0 5px rgba(0,0,0,0.1);
  }
}
A
.container {
  border: 1px solid #ccc;
  padding: 1rem;
  background: white;
  box-shadow: 0 0 5px rgba(0,0,0,0.1);
}
B
.container {
  border: 1px solid #ccc;
  padding: 1rem;
  background: white;
}
.container {
  box-shadow: 0 0 5px rgba(0,0,0,0.1);
}
C
.container {
  border: 1px solid #ccc;
  padding: 1rem;
  box-shadow: 0 0 5px rgba(0,0,0,0.1);
  background: white;
}
D
.container {
  border: 1px solid #ccc;
  padding: 1rem;
  background: white;
}
.box-shadow {
  box-shadow: 0 0 5px rgba(0,0,0,0.1);
}
Attempts:
2 left
💡 Hint
Remember that @content inserts the block exactly where it is placed inside the mixin.
🧠 Conceptual
intermediate
2:00remaining
What happens if @content is missing inside a mixin?
Given this Sass mixin:
@mixin highlight() {
  background-color: yellow;
  @content;
  border: 1px solid orange;
}

What will happen if you include it without providing a content block like this?
.note {
  @include highlight();
}
SASS
@mixin highlight() {
  background-color: yellow;
  @content;
  border: 1px solid orange;
}

.note {
  @include highlight();
}
AThe .note class will have yellow background and orange border, but no extra styles inside.
BIt will cause a syntax error because @content is required.
CThe mixin will be ignored and .note will have no styles.
DThe .note class will be empty because @content is missing.
Attempts:
2 left
💡 Hint
Think about what @content does when no block is passed.
❓ selector
advanced
2:00remaining
How does @content affect nested selectors inside a mixin?
Look at this Sass code:
@mixin button-style() {
  padding: 0.5rem 1rem;
  border-radius: 0.25rem;
  @content;
  &:hover {
    background-color: #eee;
  }
}

.btn {
  @include button-style() {
    background-color: blue;
    color: white;
  }
}

What CSS will be generated for the .btn:hover selector?
SASS
@mixin button-style() {
  padding: 0.5rem 1rem;
  border-radius: 0.25rem;
  @content;
  &:hover {
    background-color: #eee;
  }
}

.btn {
  @include button-style() {
    background-color: blue;
    color: white;
  }
}
A
.btn:hover {
  background-color: blue;
  color: white;
}
B
.btn:hover {
  background-color: #eee;
}
C
.btn:hover {
  background-color: #eee;
  background-color: blue;
  color: white;
}
DNo .btn:hover selector is generated.
Attempts:
2 left
💡 Hint
Remember that @content inserts styles inside the main selector, but &:hover is a nested selector inside the mixin.
❓ rendering
advanced
2:00remaining
What visual effect will this Sass code produce?
Given this Sass code:
@mixin card() {
  border: 2px solid black;
  padding: 1rem;
  background: white;
  @content;
}

.article {
  @include card() {
    box-shadow: 0 4px 6px rgba(0,0,0,0.1);
    border-radius: 0.5rem;
  }
}

What will the .article box look like in a browser?
SASS
@mixin card() {
  border: 2px solid black;
  padding: 1rem;
  background: white;
  @content;
}

.article {
  @include card() {
    box-shadow: 0 4px 6px rgba(0,0,0,0.1);
    border-radius: 0.5rem;
  }
}
AA white box with a black border, some padding, a subtle shadow, and rounded corners.
BA white box with a black border and padding but no shadow or rounded corners.
CA box with only shadow and rounded corners but no border or padding.
DA transparent box with no visible border, shadow, or padding.
Attempts:
2 left
💡 Hint
The @content block adds extra styles inside the box.
❓ accessibility
expert
3:00remaining
How can @content help improve accessibility in Sass components?
You want to create a reusable button style mixin that allows adding accessible focus styles via @content. Which approach below correctly uses @content to insert focus styles while keeping the base styles consistent?
@mixin accessible-button() {
  padding: 0.75rem 1.5rem;
  border: none;
  background-color: #007BFF;
  color: white;
  cursor: pointer;
  @content;
}

How should you include this mixin to add a visible focus outline for keyboard users?
SASS
@mixin accessible-button() {
  padding: 0.75rem 1.5rem;
  border: none;
  background-color: #007BFF;
  color: white;
  cursor: pointer;
  @content;
}

.button {
  @include accessible-button() {
    &:focus-visible {
      outline: 3px solid #FFD700;
      outline-offset: 2px;
    }
  }
}
AAdd focus styles outside the mixin, separately targeting .button:focus-visible.
BUse JavaScript to add focus styles instead of Sass @content.
CAdd focus styles inside the mixin before @content without using a content block.
DInclude the mixin with a content block that adds &:focus-visible styles inside the button selector.
Attempts:
2 left
💡 Hint
Think about how @content lets you add custom nested selectors inside a reusable style block.

Practice

(1/5)
1. What is the main purpose of @content in Sass?
easy
A. To pass custom styles into a mixin for flexible reuse
B. To define variables inside a mixin
C. To import external CSS files
D. To create loops in Sass

Solution

  1. Step 1: Understand what @content does

    @content allows you to insert custom CSS blocks inside a mixin, making it flexible.
  2. Step 2: Compare with other options

    Variables, imports, and loops are different Sass features unrelated to @content.
  3. Final Answer:

    To pass custom styles into a mixin for flexible reuse -> Option A
  4. Quick Check:

    @content = custom styles in mixin [OK]
Hint: Remember: @content inserts custom styles inside mixins [OK]
Common Mistakes:
  • Confusing @content with variables or imports
  • Thinking @content creates loops
  • Assuming @content is for defining selectors
2. Which of the following is the correct syntax to use @content inside a mixin?
easy
A. @mixin example { @include content; }
B. @mixin example { content(); }
C. @mixin example { @content; }
D. @mixin example { content; }

Solution

  1. Step 1: Recall the syntax for content blocks

    Inside a mixin, @content; is used to insert the passed block.
  2. Step 2: Check each option

    Only @mixin example { @content; } uses @content; correctly with the semicolon.
  3. Final Answer:

    @mixin example { @content; } -> Option C
  4. Quick Check:

    Correct syntax uses @content; inside mixin [OK]
Hint: Use @content; with a semicolon inside mixins [OK]
Common Mistakes:
  • Omitting the @ symbol before content
  • Using parentheses like a function call
  • Forgetting the semicolon after @content
3. What will be the output CSS of this Sass code?
@mixin card {
border: 1px solid black;
padding: 1rem;
@content;
}

.box {
@include card {
background-color: yellow;
}
}
medium
A. .box { border: 1px solid black; padding: 1rem; } .box { background-color: yellow; }
B. .box { border: 1px solid black; padding: 1rem; background-color: yellow; }
C. .box { background-color: yellow; }
D. Syntax error, no output

Solution

  1. Step 1: Understand mixin with @content

    The mixin card adds border and padding, then inserts the passed block with @content.
  2. Step 2: Check how .box includes the mixin

    The block inside @include card { ... } adds background-color: yellow; inside the mixin's content.
  3. Final Answer:

    .box { border: 1px solid black; padding: 1rem; background-color: yellow; } -> Option B
  4. Quick Check:

    Mixin + @content block = combined styles [OK]
Hint: Mixin styles + @content block styles combine inside selector [OK]
Common Mistakes:
  • Thinking @content styles appear outside the selector
  • Expecting separate CSS blocks for mixin and content
  • Assuming syntax error due to block usage
4. Identify the error in this Sass code using @content:
@mixin highlight {
background: yellow;
@content
}

.text {
@include highlight {
color: red;
}
}
medium
A. Missing semicolon after @content
B. Mixin name should be @content
C. Cannot use blocks with @include
D. Background property is invalid

Solution

  1. Step 1: Check syntax of @content inside mixin

    @content must end with a semicolon to be valid.
  2. Step 2: Verify other parts

    Mixin name and block usage are correct; background property is valid CSS.
  3. Final Answer:

    Missing semicolon after @content -> Option A
  4. Quick Check:

    @content requires semicolon [OK]
Hint: Always put semicolon after @content inside mixins [OK]
Common Mistakes:
  • Omitting semicolon after @content
  • Confusing mixin and content names
  • Thinking block usage with @include is invalid
5. You want to create a reusable button style mixin that allows custom hover styles using @content. Which Sass code correctly achieves this?
hard
A. @mixin button { padding: 1rem; border: none; @content; &:hover { @content; } }
B. @mixin button { padding: 1rem; border: none; @content; } .btn:hover { @content; }
C. @mixin button { padding: 1rem; border: none; } .btn { @include button; &:hover { @content; } }
D. @mixin button { padding: 1rem; border: none; @content; &:hover { @content; } } .btn { @include button { color: blue; &:hover { color: red; } } }

Solution

  1. Step 1: Understand the goal

    Create a mixin that sets base button styles and allows custom styles including hover via @content.
  2. Step 2: Analyze each option

    @mixin button { padding: 1rem; border: none; @content; &:hover { @content; } } .btn { @include button { color: blue; &:hover { color: red; } } } defines the mixin with @content inside and inside &:hover, then includes it with a block that passes normal and hover styles. This correctly applies custom hover styles.
  3. Step 3: Why others fail

    @mixin button { padding: 1rem; border: none; @content; &:hover { @content; } } tries to use @content twice in the mixin without passing blocks properly. @mixin button { padding: 1rem; border: none; @content; } .btn:hover { @content; } applies hover styles outside the mixin, losing reusability. @mixin button { padding: 1rem; border: none; } .btn { @include button; &:hover { @content; } } misuses @content outside mixin context.
  4. Final Answer:

    @mixin button { padding: 1rem; border: none; @content; &:hover { @content; } } .btn { @include button { color: blue; &:hover { color: red; } } } -> Option D
  5. Quick Check:

    Mixin with @content block for hover = @mixin button { padding: 1rem; border: none; @content; &:hover { @content; } } .btn { @include button { color: blue; &:hover { color: red; } } } [OK]
Hint: Pass hover styles inside @include block with nested &:hover [OK]
Common Mistakes:
  • Using @content outside mixin
  • Trying to call @content multiple times without blocks
  • Defining hover styles outside mixin losing flexibility
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