Write less code with CSS variables

Tram Ho

Certainly, working with CSS everyone has heard of the concept of variables,

We can declare variables in CSS as follows

And then reuse these variables in many places, which makes it easier to maintain the code

In addition to this usage, we can override variables to reduce the need to rewrite the code over and over again.

Override variables

Suppose we have the following elements

To apply modifiers to the class box we will have to write the following

As we can see above, writing normally takes a lot of code, and this is where CSS variables come into play

In addition to the above case, we can apply how to many other cases

Using CSS variables will help us avoid having to repeat the code over and over again

Share the news now

Source : Viblo