Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

CSS custom properties placement :root vs body/html tags

What is the point to define global CSS custom properties in a :root instead of body or html tags. Is this will lead to different effects or perfomance issues?

like image 994
Vladyslav Semeniuk Avatar asked Mar 13 '26 11:03

Vladyslav Semeniuk


1 Answers

Well, it might be weird initially, but it is nothing about it except specificity. :root is actually html itself with a higher specificity, so the main reason for putting variables in :root element is because we are not only using them in CSS but also in SVG and XML. So we may call :root global scope as its usage. You can also read more about their differences.

like image 164
SMAKSS Avatar answered Mar 16 '26 04:03

SMAKSS



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!