Mixins
Reuse declarations with mixins and @include.
What you will be able to do
- Declare with @mixin name($args).
- Include with @include name(args).
- Use defaults for optional arguments.
- Keep mixins focused on one pattern.
In plain English
A mixin is a reusable block of declarations with optional arguments. Use it for patterns such as focus rings, truncation or responsive breakpoints. Do not turn every rule into a mixin.
@mixin focus-ring($color: #2f74c0) {
outline: 2px solid $color;
outline-offset: 2px;
}
.button {
&:focus-visible { @include focus-ring; }
}Your turn
MediumDeclare a mixin
Declare a mixin named truncate that hides overflow and adds an ellipsis.
SCSS · starter
@mixinCheck your understanding before moving on.
Knowledge checkQuestion 1
Which directive applies a mixin?
Select an answer to continue
Study tools
Make it yours.
Keep a private note for this lesson, then turn the key ideas into flashcards you can revisit.
Sign in to save notes and flashcards.Both are private to your account and stay with your progress.
Sign inFinished reading?
Lock in what you just learned.
0%
Mark this lesson complete to save your place and move one step closer to the certificate.