Andrew Gilliland

Custom Properties

Last Updated: September 5, 2024

Custom properties, also known as CSS variables, help you declare reused values in your CSS. This is very useful for DRY code and creating design systems in CSS.

Here's how you use them:

div {
  --theme-color: black;
  background-color: var(--theme-color);
}

To be able to reference a custom property globally, declare it on the :root pseudo-class.

:root {
  --theme-color: black;
}

Resources

Using CSS custom properties | MDN