0
0
SASSmarkup~8 mins

Variable declaration with $ in SASS - Browser Rendering Trace

Choose your learning style9 modes available
Render Flow - Variable declaration with $
Read SASS file
Parse $variable declarations
Store variables in memory
Replace variable references with values
Compile to CSS
Browser renders CSS
The SASS compiler reads the file, finds variables declared with $, stores their values, replaces all uses of these variables with their values, then outputs standard CSS for the browser to render.
Render Steps - 3 Steps
Code Added:$main-color: #3498db;
Before
[ ]
No styles applied, plain div with text 'Hello'
After
[ ]
No visible change yet, variable declared but not used
Declared a variable $main-color with a blue color value. No visual change because variable is not applied yet.
🔧 Browser Action:Stores variable in SASS memory during compilation
Code Sample
A blue box with white text and padding, styled using SASS variables for color and padding.
SASS
<div class="box">Hello</div>
SASS
$main-color: #3498db;
$padding-size: 1.5rem;

.box {
  background-color: $main-color;
  padding: $padding-size;
  color: white;
  border-radius: 0.5rem;
}
Render Quiz - 3 Questions
Test your understanding
After step 3, what visual change do you see on the box?
AThe box has no background color and no padding
BThe box has a blue background, white text, padding, and rounded corners
CThe box text color changes to black only
DThe box disappears from the page
Common Confusions - 2 Topics
Why doesn't changing $main-color alone change the box color in the browser?
Because variables only affect styles where they are used. If you change $main-color but don't recompile or don't use it in any CSS property, the browser won't see any change.
💡 Variables must be used in CSS properties and the SASS must be compiled again to see changes.
Can I use variables before declaring them?
No, variables must be declared before they are used in SASS. Using a variable before declaration causes an error or no effect.
💡 Declare variables at the top of your SASS file.
Property Reference
PropertyValue AppliedVisual EffectCommon Use
$main-color#3498dbSets background color to blueConsistent color usage
$padding-size1.5remAdds space inside the box around textUniform spacing
colorwhiteText color changes to whiteText readability
border-radius0.5remRounded corners on box edgesSoft visual style
Concept Snapshot
$ declares a variable in SASS Variables store reusable values like colors or sizes Variables must be declared before use SASS replaces variables with values during compilation Final CSS has no variables, only values Using variables makes styling consistent and easy to update