Both mixins and functions accept parameters the same way. This lesson focuses specifically on parameter mechanics: default values, named arguments at the call site, and variable-length argument lists using the ... syntax.
How Sass Parameters Work
Parameters are declared inside the parentheses of a @mixin or @function definition, optionally with a default value. At the call site, arguments can be passed positionally (in order) or by name, which can appear in any order and improves readability for optional parameters.
$param: default gives a parameter a fallback value if the caller omits it.
$rest... collects any remaining positional arguments into a list.
Named arguments ($param: value) can appear in any order at the call site.
Positional arguments must come before named arguments in the same call.
Parameters Cheatsheet
Common parameter patterns for mixins and functions alike.
Pattern
Example
Behavior
Required parameter
@mixin box($width)
Caller must supply a value
Default parameter
@mixin box($radius: 0)
Falls back if omitted
Dependent default
@mixin box($h: $w)
Defaults to another parameter's value
Variable arguments
@mixin shadow($shadows...)
Collects extra args into a list
Spreading a list
@include shadow($list...)
Expands a list into positional args
Named call
@include box($radius: 8px)
Skips earlier defaults explicitly
Default Parameter Values
Default values make a parameter optional. They are evaluated at call time, so a default can reference another parameter, or even call a function, as long as everything it depends on is already available.
The ... syntax, called "argument globbing", lets a mixin or function accept any number of positional arguments, collected into a single list variable inside the body.
Any number of shadow values can be passed; they're joined into one comma-separated box-shadow value.
Spreading a List as Arguments
The same ... syntax can also be used at the call site to "spread" an existing list or map into a function or mixin's positional (or keyword) arguments, the reverse of argument globbing.
Passing a positional argument after a named argument in the same call, which is invalid syntax.
Assuming default parameter values are evaluated once globally, they're actually evaluated fresh at every call.
Forgetting the ... when trying to spread an existing list into a mixin or function call, resulting in the whole list being treated as a single argument.
Overloading a single mixin with too many optional parameters instead of splitting it into smaller, more focused mixins.
Key Takeaways
Parameters can have default values, evaluated fresh at every call.
Named arguments can appear in any order and are especially useful for optional parameters.
The ... syntax collects extra positional arguments into a list (argument globbing) or spreads a list into arguments (the reverse).
Positional arguments must always precede named arguments within the same call.
Pro Tip
When a mixin accumulates more than four or five parameters, it's often a sign to accept a single Sass map instead, @mixin card($config: (radius: 8px, shadow: true)), which keeps call sites readable as options grow.
You now understand parameters for both mixins and functions. Next, explore Sass's core data types before working with operators, colors, lists, and maps.