🌐CSS Custom Properties
Also known as CSS Variables, CSS Variable, var(), --custom-property
Named values in CSS, like --brand, that you set once and reuse all over the page.
Think of it like
It is like a paint pot with a name. Change the paint in the pot, and every wall changes.
Example
Emma's site uses one teal in 40 places. She makes it --brand, so a new brand colour is now a one-line change.
Why it matters
Themes like dark mode become easy. You swap a few values, and the whole page follows.
Definition
Example code
css
:root { --brand: teal; }
.button { background: var(--brand); }
.link { color: var(--brand, blue); }Common mistake
Key takeaways
- 1Two dashes. Names start with --.
- 2Read with var(). Add a backup after a comma.
- 3They pass down. Children get the value of their parent.