Sass/SCSS Variables
Defining and using variables in Sass
Variable Declaration
$primary-color: #3498db; # define variable
$font-stack: Arial, sans-serif;
$base-padding: 1rem;
Using Variables
.button {
background-color: $primary-color; # use variable
font-family: $font-stack;
padding: $base-padding;
}
Variable Scope
$global-var: blue; # global variable
.container {
$local-var: red; # local to container
color: $local-var;
}
Default Values
$color: red !default; # use this value if not already set
Interpolation
$name: primary;
.alert-#{$name} { # interpolate in selector
background: blue;
}