Custom Properties
With CSS custom properties (often called CSS variables), we have a way to store a value for use in several CSS declarations. We can change this value as we like.
The syntax for a CSS custom property is a name prefixed with two dashes (--
). We can then use the value stored in the property with the CSS var
function. Here is an example of some CSS custom properties in use:
<style> Â :root { Â Â Â Â Â Â --dark-text-color: #131313; Â Â Â Â Â Â --light-text-color: #cfcfcf; Â } Â p.dark { Â Â Â Â Â Â color: var(--dark-text-color); Â } Â p.light { Â Â Â Â color: var(--light-text-color); Â } </style>
The following screenshot shows the result of applying the preceding style rules to one paragraph element with the dark class attribute applied and one paragraph element with the light class attribute applied. The color variables we have created...