+ 2

Why we use variables in CSS when we can use Classes for same purpose??

I'm beginner in HTML/CSS so I've this doubt, kindly reply me. Thank you :)

29th Oct 2020, 11:44 AM
Rupali Haldiya
Rupali Haldiya - avatar
3 Answers
+ 5
i get you. we can easily change a style property by changing its classes, which is very true. but what if there are a property that need to be change across different class and rules that you can toggle ? for example a color and background color in dark theme ? you would need to write another set of same classes, with slight modification in each property of it. which can be pretty tedious on the larger css file. variable give a solution to this problem, instead of rewriting every claass you'll only need to change the variable value and everything can be change
29th Oct 2020, 11:55 AM
Rei
Rei - avatar
+ 2
Actually we cant use classes for variables. they are extremely to other things. Variables are containers that store some value
29th Oct 2020, 11:47 AM
Steve Sajeev
Steve Sajeev - avatar
+ 2
Yeah! I got it! Thnx to both :)
29th Oct 2020, 12:24 PM
Rupali Haldiya
Rupali Haldiya - avatar