SystemTutor
About
Sign in
Loading course documentation…
SystemTutor

COURSES

  • Data Structures & Algorithms
  • CSS MasterclassNew course
  • System DesignNew course

PRACTICE

  • Algorithm practice
  • CSS practice

LEGAL

  • Privacy Policy
  • Terms of Service
  • About

© 2026 SystemTutor. All rights reserved.

Built with 🫶 by Shatlyk

Welcome to CSS
CSS Values and Responsive SizingCSS UnitsCSS Custom PropertiesCSS FunctionsFluid SizingDesign Tokens Choosing units and tracing values
Values and Units

Design Tokens

Share reusable values using scope and inheritance.

A design token is a name for a reusable design decision, such as an accent color, card spacing, or corner radius. Reusing that name keeps related elements consistent.

In this lesson, CSS custom properties represent those decisions in a stylesheet. A custom property is the CSS mechanism; it becomes a useful token when its name communicates a design role. The Design Tokens Community Group format specification describes a format for sharing tokens between tools, but here you will work directly in CSS.

Name shared decisions

Start with three tokens:

:root {
  --color-accent: green;
  --space-card: 1rem;
  --radius-card: 0.5rem;
}

The names describe their purpose, rather than their current literal value:

  • --color-accent: The accent used by related interface elements.
  • --space-card: The spacing used inside a card.
  • --radius-card: The card's corner radius.

For example, --color-accent can later change from green to purple without making its name misleading. A name such as --green describes the current value rather than its role.

Change a shared value in one place to update every declaration that uses it. For example, changing --space-card updates the spacing wherever var(--space-card) appears.

Use the tokens in a component

Consider two theme panels:

:root {
  --color-accent: green;
  --space-card: 1rem;
  --radius-card: 0.5rem;
}

.card {
  color: var(--color-accent);
  padding: var(--space-card);
  border: 2px solid var(--color-accent);
  border-radius: var(--radius-card);
}

Both cards use the root values: green text and borders, 1rem of padding, and 0.5rem corner radii.

The component describes how to use each decision. The token definitions supply the actual values. This separation is useful because the same .card rule can work in more than one theme without repeating its properties.

Override a token within a section

Add a local override:

.panel.featured {
  --color-accent: purple;
}

Only the featured card gets purple text and a purple border. Its padding and radius stay the same:

  • The featured panel receives its own --color-accent value.
  • Its card inherits that local value.
  • The other panel keeps the root value because it is outside the featured panel's descendants.

The order-processing card has green text and border. Its featured sibling has purple text and border. Both retain the same padding and corner radius.

The card rule stays reusable because it refers to the token. There is no need to repeat the text and border declarations for the featured version.

Trace the accent value

Follow color: var(--color-accent) for each card:

  1. For the first card, --color-accent is inherited from :root, so var() supplies green.
  2. The featured panel has its own --color-accent: purple declaration. That declaration wins on the panel and is inherited by its card, so var() supplies purple there.
  3. The first card is not inside the featured panel, so it still inherits the root value.

The .card rule does not need to change. The value changes because var() reads the custom property available at each card's position in the document tree.

Explain the override

Why can one .card become purple even though both cards match the same .card rule? Explain the roles of inheritance and var(); do not just say that the featured panel has a different color.

Trace the accent from parent to card

A custom property applies to the element where you define it and can pass down to its children. It does not pass up to parents or across to siblings.

If several declarations set the same custom property on the same element, the cascade chooses the value. A value declared directly on a child also takes precedence over one it would otherwise inherit.

That gives you a useful pattern:

  • Put shared defaults on :root.
  • Override a value on a section when its descendants need a variation.
  • Define a value directly on a component when that component needs its own setting.

Try it yourself

Try it yourself

Theme two cards through shared tokens

HTML + CSS

Loading code editor…

Live preview

Updating…

Final output

No comparison yetChecks after 3s without edits
Loading your draft…

Key Takeaways

  • Design tokens: Named design decisions keep related styles consistent.
  • Custom properties: CSS can store tokens in reusable -- values.
  • Scope: Ordinary custom properties reach the declaring element and its descendants.
  • Local variation: Override a token on a section to change its descendants without repeating component rules.
  • Cascade: Competing token declarations follow the same priority rules as other CSS declarations.

Take the quiz · Choosing units and tracing values

How is this lesson?

Previous lessonFluid SizingNext lesson Choosing units and tracing values
Edit on GitHubReport on GitHub
On this page
%

On this page

Name shared decisionsUse the tokens in a componentOverride a token within a sectionTrace the accent valueExplain the overrideTrace the accent from parent to cardTry it yourselfKey Takeaways