How to Use CSS Custom Properties for a Design System
A beginner, hands-on guide to use css custom properties for a design system with browser inspection, exact code-level changes and verification.
By the end: You will implement and verify use css custom properties for a design system on a real local/staging page.
You will implement and verify use css custom properties for a design system on a real local/staging page.
Key terms before you start
These definitions make the steps easier to follow and help distinguish controls, files and concepts that can look similar at first.
What you need before starting
- A page you are allowed to edit
- Access to the HTML/CSS/JS or CMS/template that renders it
- A modern browser with Developer Tools
Step-by-step tutorial
Every step is shown below. Work through them in order and use each checkpoint to confirm the result before moving on.
Work on a local or staging copy
Open the project containing the website source. If this is a production site, use a staging copy or backup before structural changes.
A browser page is rendered from source files/CMS output; DevTools edits do not save back to the server.
Move it into the actual source and reload.
Open the page in a modern browser
Load the page, then press F12 or Ctrl+Shift+I (Windows/Linux) to open Developer Tools.
DevTools lets you inspect the DOM, applied CSS, computed sizes, requests and console errors.
Move it into the actual source and reload.
List repeated design decisions
Collect actual text/accent/surface colors, spacing and radii used repeatedly.
Do not create tokens for values that appear once without a design reason.
Move it into the actual source and reload.
Define variables in :root
Add --color-text, --color-accent etc. to :root.
Custom property names begin with -- and participate in the cascade.
Replace repeated literals gradually
Change component rules from raw values to var(--...).
Make small replacements and visually test each group.
Name by role
Prefer --color-text to --gray-900 when the token means “body text”.
Role names make theme swaps more understandable.
Check caching, loaded asset URL, theme/template and logged-out view.
Override within a component/theme scope
Redefine a variable on .dark-section or component root where a contextual value differs.
You can inherit values without duplicating all child rules.
Check caching, loaded asset URL, theme/template and logged-out view.
Change one token as a test
Modify --color-accent and inspect all consuming components.
This reveals accidental hard-coded values.
Test the public/staging URL logged out
Open the final URL in a private/incognito window.
CMS/admin sessions can hide caching, permission or styling differences.
Check caching, loaded asset URL, theme/template and logged-out view.
Document the changed file/rule
Record the file/template/component and purpose of the change in the project notes or version-control commit.
Future maintainers should not have to reverse-engineer why a rule exists.
Check caching, loaded asset URL, theme/template and logged-out view.
Reload the real page and reproduce the result after all temporary DevTools edits are gone.
Concrete examples
Copyable example
:root {
--color-text:#17191f;
--color-accent:#f35120;
--space-1:.5rem;
--space-2:1rem;
--radius-card:1rem;
}
.card { padding:var(--space-2); border-radius:var(--radius-card); }Troubleshooting
Move it into the actual source and reload.
Check caching, loaded asset URL, theme/template and logged-out view.
Use the Styles/Computed panels to trace the final value instead of adding stronger selectors blindly.
The change has a traceable reason/location.
Continue with these tutorials
Documentation and references
Use these primary and supporting sources to verify current controls, browser behavior and product-specific details.