← TechnologyThe essentials of

CSS variables: common values with a clear purpose

Publisher: ResumeMaker • 2 sources

Published: 22 Oct 2026 13:13 · Updated: 22 Oct 2026 13:13

AI source check: 20 Oct 2026 22:11. This is not editorial approval.

In a few sentences

In brief

Custom properties allow values to be named and reused. Inheritance and cascade determine which value the particular item receives.

Useful to know

In an interface, the same colors, distances, and sizes are often repeated. If each value is recorded separately in many places, the change requires careful searching. CSS custom properties allows values to be named and reused. The usual record starts with two hyphens, and access is through the var. function This helps not only with editing, but also with reading: the name can explain the purpose that a numeric or color value alone does not indicate. [1]

These properties are involved in the cascade, and the values usually defined by two dashes are inherited. [1] This means that the place of definition matters. A common value can be set high in the structure, and a separate component can replace it for its own area. It is useful to use this opportunity consciously. Otherwise, a long sequence of redefinitions can make the final color as difficult to find as with multiple literal values.

Let's imagine a fictional catalog of primary and secondary buttons. Instead of all blue values being combined just because they look the same today, we can ask what role each color has. The connection color and message color may coincide temporarily, but serve different solutions. The choice of names should reflect these roles. Thus, a future change of messages will not necessarily change all the links on the site.

The var function is used in values of CSS properties. It is not a common mechanism for replacing property names or selectors. There may also be a backup value that is used under the right conditions. [2] This distinction is important when reading an example: the convenience of syntax does not mean that it works anywhere in the style. It is good for each small demonstration to show where the value is set and which item actually receives it.

In a practical check, we can change a role and traverse the components that use it. If the goal is only the main button, we check whether the secondary and messages have remained as expected. Then we look at a local redefinition in a specific section. This verification is more meaningful than proving that a variable exists. The final result in the interface and its compliance with the chosen purpose is important.

In maintenance, it is useful for common names to be few and consistent, and for specific ones to describe their component. It is not necessary for each number to automatically receive a name. The question is whether reuse or meaning justifies the total value. CSS custom properties provide a mechanism for this solution. Quality comes from clear roles, predictable inheritance, and checking that an edit changes exactly those parts of the page that should have been linked.

Sources

For further detail and to check the information:

  1. [1] MDN — Using CSS custom properties ↗
  2. [2] MDN — var() ↗