Mixins let you define styles once and reuse them throughout your stylesheet. Write @mixin name { … } or @mixin name($args…) { … }, then drop them into context with @include name or @include name($args…).
They help you avoid non-semantic classes like .float-left and distribute style collections in libraries. Prefer mixins when you need to emit CSS; use @function when you only need to compute a value.
Official pattern.
Per the Sass docs: compose mixins (include one inside another), pass arguments for customization, and use @content when callers should inject their own style block.
Hyphens = underscores.
Like other Sass identifiers, reset-list and reset_list refer to the same mixin.
Compile-time only.
Mixin names never appear in CSS — only the styles they generate. Browsers never see @mixin or @include.
Pattern: define with @mixin → compose if needed → @include into a selector (or at the top level).
Reference
Args & @content
Core mixin shapes:
Form
Meaning
@mixin name { … }
Reusable style bundle (no args)
@mixin rtl($prop, $ltr, $rtl)
Required positional arguments
$x: 50%
Optional argument with a default
@include square(100px, $radius: 4px)
Keyword argument at the call site
$selectors...
Argument list — any number of extras
@content;
Inject the caller’s style block
Also used with
Related Rules
Compare with @function for pure values and @extend for semantic selector sharing. Ship mixins through @use / @forward. Guards and soft tips use @error and @warn.
Code
SCSS Examples
Each example defines and includes mixins at compile time. Open View Compiled CSS for verified output.
Offsets stack by multiplying the index by $height.
You can also spread a list: @include order(150px, $list...).
Edge Cases & Pitfalls
Most mixin bugs are wrong tool choice, content scope, or renaming public arguments.
function
Need a value? Use @function
Mixins emit styles. If you only need a computed length or color, return it from a function instead.
content
@content is lexically scoped
The content block sees variables from the include site, not locals defined inside the mixin.
rename
Keyword args are public API
Renaming a parameter can break callers. Keep the old name temporarily and @warn during migration.
css
Mixin names never ship
Do not expect a class named after the mixin. Only generated declarations and selectors appear in CSS.
Toolchain
Sass Support
@mixin / @include are core Sass at-rules. Browsers never see them — only the CSS they expand into.
Implementation
Status
Dart Sass
Supported (recommended)
LibSass / node-sass
Supported (deprecated toolchain)
Ruby Sass
Supported (end-of-life)
Browsers
N/A — only see expanded CSS
Prefer Dart Sass for new projects. SCSS and indented syntax both support mixins (indented also has legacy = / + shorthand — prefer @mixin / @include).
Remember
Key Takeaways
Reuse styles:@mixin defines; @include expands.
Customize with args, defaults, keywords, and $args....
@content lets callers inject a style block into the mixin.
Emit CSS with mixins; compute values with functions.
One line: mixins are compile-time style templates you include wherever you need them.
Compile
Compile Notes
@mixin / @include never reach the browser. Conceptual flow:
flow.txt
1. Define @mixin (args / @content optional)
2. @include it in a selector or at the top level
3. Bind arguments; inject @content if provided
4. Expand generated CSS into the current context
5. Emit finished rules — mixin names are gone
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.