Custom Properties Variables
suggest changeIntroduction
CSS Variables allow authors to create reusable values which can be used throughout a CSS document.
For example, it’s common in CSS to reuse a single color throughout a document. Prior to CSS Variables this would mean reusing the same color value many times throughout a document. With CSS Variables the color value can be assigned to a variable and referenced in multiple places. This makes changing values easier and is more semantic than using traditional CSS values.
Syntax
- :root {} /* pseudo-class that allows for more global definition of variables */
- –variable-name: value; /* define variable */
- var(–variable-name, default-value) /* use defined variable with default value fallback */
Remarks
Custom properties are standard and are supported in current browsers. Internet Explorer never implemented them. See var().
Found a mistake? Have a question or improvement idea?
Let me know.
Table Of Contents