CSS now can have VARIABLES | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
+ 5

CSS now can have VARIABLES

CSS now supports variables like JavaScript does. it store the variables in the root element and is accessed with the "var()" syntax. The below code shows how to store "red" as the background-color of a div with name bgc... /*css*/ html{ --bgc: red; } div{ background-color: var(--bgc); } ...here "--bgc" was defined in the topmost parent element of the document(html || :root) and later accessed with the var(value) syntax on the target property. https://code.sololearn.com/WYFh7a5Uup6i/?ref=app

22nd Feb 2018, 5:01 AM
Nomeh Uchenna Gabriel
Nomeh Uchenna Gabriel - avatar
1 Answer
+ 3
Still experimental, so support depends of browsers/versions ( and IE should never support them, while Edge seems only -- good -- support from version 16... ) https://caniuse.com/#feat=css-variables Anyway, documentation about that feature is available from a while... https://developer.mozilla.org/en-US/docs/Web/CSS/Using_CSS_variables https://developer.mozilla.org/en-US/docs/Web/CSS/--*
22nd Feb 2018, 9:20 AM
visph
visph - avatar