Cascading CSS Variables

Introduction

Cascading variables or CSS variables officially called custom properties are entities which behave similarly to traditional variables. In that variables allow for data to be stored and updated to reflect new values later2.

Where to Start?

CSS variables are defined to contain specific values and be reused throughout a document. They are set using custom property notation (e.g., `--main-color: black`) and are accessed using the `var()` function (e.g., `color: var(--main-color)`)1. Declare the CSS variable in the `:root` or `body` selectors for global access. When maintaining complex CSS documents, it is not only beneficial to use CSS Variables but also smart. When making future updates instead of searching potential hundreds of lines of code, one only needs to update the necessary CSS variable1.

Syntax Examples

References

1. Visit MDN's Cascading CSS variables page for more information.

2. A Practical Guide to CSS Variables (Custom Properties) by Maria Antonietta Perna.