Sass Variables
Sass Variables
Sass Variables are used to store values like colors, fonts, sizes, spacing, and reusable data that you can use again and again in your stylesheet.
They make your CSS cleaner, consistent, and easier to maintain.
Variable Syntax in Sass
In Sass, variables start with the $ symbol.
Using Variables
✔ If you change $main-color, it updates everywhere.
Types of Sass Variables
1️⃣ Color Variables
2️⃣ Number Variables
3️⃣ String Variables
4️⃣ Boolean Variables
(Used mainly with conditions & mixins)
5️⃣ List Variables
6️⃣ Map Variables (Key–Value Pair)
Variable Scope
Global Variable
Local Variable
⚠️ Local variables work only inside that block.
Default Variables (!default)
Used when you want to override variables later.
Variable Interpolation
Use variables inside strings or selectors.
Output:
Real-Life Example
Benefits of Sass Variables
✔ Easy theme changes
✔ Consistent design
✔ Less repetition
✔ Faster development
📌 Summary
-
Variables start with
$ -
Can store colors, numbers, strings, lists, maps
-
Support scope & default values
-
Improve code readability & maintenance
