Content blocks with @content let you pass a chunk of styles into a mixin. This helps you reuse code and keep your styles organized.
Content blocks with @content in SASS
@mixin mixin-name { /* common styles here */ @content; }
The @content directive is a placeholder for styles passed when you include the mixin.
You use @include mixin-name { ... } to pass the styles inside the curly braces.
@mixin box { border: 1px solid black; padding: 1rem; @content; } .container { @include box { background-color: lightblue; } }
@mixin button-style { font-weight: bold; @content; } .button { @include button-style { color: white; background-color: blue; } }
This example creates a card mixin with border, padding, and background color. The @content lets you add extra styles when you include it. The .article and .note classes use the mixin but add their own unique styles inside the block.
@use 'sass:color'; @mixin card { border: 2px solid black; padding: 1.5rem; border-radius: 0.5rem; background-color: color.scale(white, $lightness: -10%); @content; } .article { @include card { box-shadow: 0 0.5rem 1rem rgba(0, 0, 0, 0.1); } } .note { @include card { background-color: color.scale(yellow, $lightness: -20%); font-style: italic; } }
You can only use @content inside mixins, not in regular selectors.
If you don't pass any content when including the mixin, @content is simply ignored.
Using @content helps keep your Sass modular and easier to maintain.
@content lets you pass custom styles into a mixin.
Use it to create flexible, reusable style blocks.
It keeps your code clean and avoids repetition.