Every website has it's unique front-end design. Whether it is brand-color, text-color, background colors, font-family etc. It is very likely that 'title color of website is different than it's content color' or the links text color is same as title color.

In CSS, we just need to create the class name which we can be use whenever we need that style.

Let's have a look on these conditions to understand what we are upto.

Case 1:

In CSS we have to write the above condition like this.

nav a{color:#1266ae;}

Yes, we know that the third line of code can be written with first line of code separated by comma. like this,

nav a, .title{color:#1266ae}

But what if we need some extra features in title class.?

.title{color:#1266ae, font-size:24px; font-weight:bold;}

If the above code snippet is the requirement then we have to get back to our first code block as we never like to make our navigation same as title having font-size:24px.

Case 2:

What if you have almost designed the project and then client asks to change the text-colors, background, navigation link colors? Yes. It happens so many times in front-end designing. So tie your seat-belt, start find and replace all that colors and background-color every where you possibly have written it.

Using variable in Sass eliminate all that tough and time consuming job in phew..!

In Sass we can define the variable for all that at one place and use it anywhere we need it. Let's have an example to make it clear.


.content {

Which will compile to 

nav a{

So, whenever we have any such cases we just need to change the values in variable we have defined and sass will take care of rest automatically. Pretty good. Huh.?

Sass supports arithmetic operations. We can divide, multiply, subtract, add, calculate modulus. So this becomes savior as we do not have to write exact size of a font, width height etc. For example,

We want to create a div with width 100px, height 80px, padding 5px.

To do so we will write,

$darkgrey: lighten($black, 25%);

which is compiled to


So, days are gone when you need to pick the colors using color-pickers and paste hex-values for every different colors.
We just need to use color functions to adjust and generate variation in colors.

Below are the most common color functions

  • rgb($red, $green, $blue)
  • rgba($red, $green, $blue, $alpha)
  • hsl($hue, $saturation, $lightness
  • lightness($color)
  • lighten($color, $amount)
  • darken($color, $amount)
  • grayscale($color)
  • mix($color1, $color2, [$weight]) etc..

As we can see, using variables in Sass is cool and time saving. 

The best practice to name variables

  • Always try to use meaningful names which explains it's purpose.
  • Do not make too long or too short variable names. It may create confusion.
  • It is advisable to use project or brand name of company in variables. For example- Brand-color, brand-tag-line etc..
  • Never use similar variable names like - employee and employees, It will be better to name as employee and all-employee 
  • Always use global languages for naming variables, so that every developers can understand it.
  • Using verbs in variable is good practice. like for navigation drop-down- has-child, is-active, processed etc..

While naming variables for colors, or borders etc., we should follow something like this

Poor Naming :



Good Naming :




As we can see, well structured variable names are easy to find and clear to view. Almost all text-editor eg; Notepad++, Coda, PhpStrom, sublime etc. has auto suggest functionalities which suggests relative phrases as we type. 

So, this will make easy to use variable by just typing '$border' and the editor will suggest all the keywords start with the same name -'border'.

So, remember to name your variables wisely next time.

If you have any issue , let us know in comment box.
Happy Coding.