Mixins let you reuse groups of CSS styles easily. A mixin library is a collection of these reusable style blocks to keep your code clean and organized.
You want to apply the same button styles in many places.
You need consistent spacing or colors across your site.
You want to avoid repeating long CSS code snippets.
You want to quickly update styles in many places by changing one mixin.
You want to share style patterns with your team.
Syntax
SASS
@mixin name($parameters) {
// CSS styles here
}
@include name($arguments);
Use @mixin to define reusable style blocks.
Use @include to apply the mixin styles where needed.
Examples
This mixin centers content using flexbox. You include it inside any selector to apply those styles.
This example shows a mixin called card that styles a box with background color, padding, rounded corners, and shadow. The .card class uses this mixin with specific values. The result is a neat card style container.
Mixins are created with @mixin but applied with @include.
Step 2: Identify incorrect usage
The code uses @mixin text-style; inside .title, which is wrong syntax.
Final Answer:
Using @mixin instead of @include inside .title -> Option C
Quick Check:
Apply mixins with @include, not @mixin [OK]
Hint: Use @include to apply mixins, never @mixin [OK]
Common Mistakes:
Confusing @mixin and @include
Adding dot before mixin name
Thinking mixins can't be used in selectors
5. You have a mixin library with multiple mixins for buttons. You want to create a new mixin primary-button that uses the existing button-base mixin and adds a blue background. Which Sass code correctly achieves this?
hard
A. @mixin primary-button { @include button-base; background-color: blue; }
B. @mixin primary-button { @mixin button-base; background-color: blue; }
C. @include primary-button { @include button-base; background-color: blue; }
D. @mixin primary-button { button-base(); background-color: blue; }
Solution
Step 1: Define new mixin with @mixin
Use @mixin primary-button { ... } to create the new mixin.
Step 2: Include existing mixin inside new one
Inside the new mixin, use @include button-base; to reuse styles.
Step 3: Add additional styles
Add background-color: blue; after including the base mixin.