0
0
SASSmarkup~8 mins

Default parameter values in SASS - Browser Rendering Trace

Choose your learning style9 modes available
Render Flow - Default parameter values
[Read @mixin with parameters] -> [Check if argument passed] -> [If no argument, use default value] -> [Compile mixin body with parameters] -> [Output CSS]
When a mixin is called, the Sass compiler checks if arguments are provided. If not, it uses the default values defined for parameters, then compiles the CSS accordingly.
Render Steps - 3 Steps
Code Added:@mixin box-shadow($shadow: 2px 2px 5px gray) { box-shadow: $shadow; }
Before
[No CSS for box-shadow]
After
[Mixin box-shadow defined with default shadow: 2px 2px 5px gray]
The mixin is defined with a default parameter value for the shadow property.
🔧 Browser Action:Sass compiler stores mixin with default parameter
Code Sample
This Sass code defines a mixin with a default parameter value for box-shadow. The .box class uses the default shadow, while .box-custom uses a custom shadow.
SASS
@mixin box-shadow($shadow: 2px 2px 5px gray) {
  box-shadow: $shadow;
}

.box {
  @include box-shadow;
}

.box-custom {
  @include box-shadow(5px 5px 10px black);
}
Render Quiz - 3 Questions
Test your understanding
After step 2, what box-shadow does the .box class have?
A2px 2px 5px gray
B5px 5px 10px black
CNo box-shadow
DDefault browser shadow
Common Confusions - 2 Topics
Why does my mixin always use the default value even when I pass an argument?
Make sure you pass the argument correctly when including the mixin. If the argument is missing or misspelled, Sass uses the default value.
💡 Passing an argument overrides the default; missing argument uses default.
Can I have multiple parameters with default values?
Yes, you can define multiple parameters with defaults. If you omit some arguments, Sass uses defaults for those omitted.
💡 Defaults fill in only missing arguments, others use passed values.
Property Reference
ParameterDefault ValueUsed WhenEffect
$shadow2px 2px 5px grayNo argument passedApplies default box-shadow style
$shadowCustom valueArgument passedApplies custom box-shadow style
Concept Snapshot
Sass mixins can have default parameter values. If no argument is passed, the default is used. Passing an argument overrides the default. Defaults provide flexibility and reduce repetition. Use @mixin with ($param: default) syntax.