🔰variables
a.k.a css custom properties
🔸 Valid Names ┊ Cheatsheet ┊ Key Points
:root {
/* ⭐️ define css vars */
--panel-bg: #fff;
--panel-color: #000;
}
.panel {
/* ⭐️ use css vars */
color: var(--panel-color);
background-color: var(--panel-bg);
}MDN ⟩ CSS functions ⟩ var()
Shadow DOM ⟩ Use CSS Variables
Element ⟩ .styleProp()
styles in shadow DOM can use variables defined in light DOM.
Valid Names
CodeSandbox ⟩ --css-var+1 valid name?
Cheatcheet
Window ⟩ .getComputedStyle() - returns an object (live
CSSStyleDeclarationobject) containing the values of all CSS properties of an element.CSSStyleDeclaration ⟩
.getPropertyValue() :
DOMString| ''.setProperty()
Element ⟩ .styleProp()
key points
The custom properties behave as a sort of scoped variable because the values are inherited by descendant elements.
redefine css vars
Last updated
Was this helpful?