In modern web development, design tokens are crucial for maintaining consistency across design systems. These named entities, which store visual design attributes like colors, spacing, and typography, are effectively implemented in CSS using custom properties (also known as CSS variables).
Saving and Managing CSS Custom Properties
CSS custom properties are typically defined within a :root selector to ensure global scope across the entire document:
Once defined, these custom properties can be accessed anywhere in the stylesheet using the var() function. The var() function retrieves the value of a custom property, allowing for consistent reuse and easy updates across multiple rules:
By leveraging custom properties and the var() function, stylesheets become more maintainable, as changes to a property’s value in the :root will automatically propagate throughout the entire CSS, reducing duplication and the risk of inconsistencies (MDN, 2025f).
By storing the results of these modern CSS functions and gradients in custom properties, design systems gain flexibility and maintainability, as these design tokens can be easily reused and updated across the entire stylesheet using the var() function.