Sass mixins let you define styles once and reuse them anywhere with @include. This page covers arguments, defaults, keyword args, argument lists, @content blocks, and five compiled examples.
01
Define
@mixin
02
Use
@include
03
Args
Required / optional
04
Keywords
$name: value
05
Content
@content
06
Practice
5 examples
Concept
What Are Mixins?
Official docs: mixins allow you to define styles that can be re-used throughout your stylesheet. They make it easy to avoid non-semantic classes like .float-left, and to distribute collections of styles in libraries.
Defined with @mixin name { … } or @mixin name($args…) { … }.
Included with @include name or @include name($args…).
Names cannot begin with --.
Hyphens and underscores are identical: reset-list = reset_list.
Mixin names never appear in CSS—only the styles they generate.
💡
Beginner tip
Think of a mixin as a reusable recipe card. @mixin writes the recipe; @include cooks it into the current selector.
Official docs: arguments let you customize a mixin each time it is included. Declare variable names in parentheses after the mixin name, then pass matching SassScript expressions in @include.
Optional arguments
Give a default with $name: value. Callers can omit that argument. Defaults can be any expression and may refer to earlier arguments.
Keyword arguments
Pass by name: @include square(100px, $radius: 4px). Especially helpful for booleans and multiple optional values.
⚠️
Renaming args
Because any argument can be passed by name, renaming a parameter can break callers. Keep old names as optional aliases for a while if you must rename.
Variadic
🔀 Taking Arbitrary Arguments
Official docs: if the last parameter ends in ..., extra positional arguments become a list (an argument list).
Pass a list with $list... to expand positional args.
Pass a map with $map... to expand keyword args.
Use meta.keywords($args) to read extra keyword arguments as a map.
Forward everything to another mixin with @include other($args...).
Blocks
📄 Content Blocks (@content)
Official docs: a mixin can take an entire block of styles. Declare @content in the mixin body; callers pass styles in braces after @include.
Icon / image replacement — shared background text tricks.
Library APIs — ship mixins via @use / @forward.
🧠 How Compilation Works
1
Define a mixin
Write styles (and optional args / @content) once.
Source
2
Include it
Pass arguments and an optional content block at the call site.
Compile
3
Expand in place
Sass copies the generated CSS into the current selector context.
Emit
4
✓
CSS ships
Browsers never see @mixin—only finished rules.
Watch Out
⚠️ Common Pitfalls
Expecting a CSS class — mixin names are not selectors.
Missing required args — every non-default parameter must be passed.
Content scope surprises — @content cannot see mixin-local variables.
Overusing mixins for one-liners — a variable or plain CSS may be clearer.
Huge CSS output — including a large mixin everywhere duplicates rules.
Pro Tips
💡 Best Practices
✅ Do
Name mixins for intent (horizontal-list, not styles1)
Use keyword args for booleans and optional knobs
Prefer @content for wrappers callers should customize
Ship mixins through @use namespaces in libraries
Keep argument lists short and documented
❌ Don’t
Use mixins as a substitute for semantic HTML/CSS
Rename public args without a migration path
Assume content blocks see mixin variables
Rely on indented = / + syntax in new SCSS
Duplicate giant mixins when a shared class would do
Summary
Key Takeaways
Knowledge Unlocked
Five things to remember about Sass mixins
Define once with @mixin, reuse with @include.
5
Core concepts
📝01
Define
@mixin name
Call
📦02
Include
@include name
Use
🔢03
Args
defaults + keywords
API
📄04
Content
@content blocks
Inject
✓05
Output
CSS only
Compile
❓ Frequently Asked Questions
Mixins are reusable groups of styles defined with @mixin and inserted with @include. They help you avoid non-semantic utility classes and share style collections in libraries.
Write @mixin reset-list { … } then @include reset-list; inside a style rule (or at the top level). Hyphens and underscores in names are treated as identical.
Yes. Declare them after the name: @mixin rtl($property, $ltr-value, $rtl-value). Pass the same number of values when you @include, or use defaults and keyword arguments.
@content injects a block of styles passed by the caller into the mixin. Write @include hover { … } and place @content; where those styles should appear.
If the last parameter ends in ..., extra positional arguments become a list (an argument list). You can also pass a list or map followed by ... into an @include.
No. Mixins are compile-time only. The mixin name never appears in CSS—only the styles they generate.
Did you know?
Official Sass docs treat hyphens and underscores as the same in mixin names—so @include reset-list and @include reset_list call the same mixin.
@mixin and @include are the core way to reuse style recipes in Sass. Start simple, add arguments and @content as APIs grow, and load shared mixins through @use in modern projects.