Quick Answer
CSS custom properties store reusable values that CSS declarations can reference with var(). Their effect depends on scope, inheritance and the cascade. Define a value once where it belongs, inspect local overrides and verify the properties that consume it. Changing one variable affects only the declarations that actually reference the resulting value.
Define and reference a value
MDN’s custom-property guide explains double-dash names, var(), inheritance and fallback behavior. This illustrative example defines a reusable spacing value:
:root {
--card-space: 1.25rem;
}
.service-card {
padding: var(--card-space, 1rem);
}
The reference is explicit. Another card with padding: 20px will not change merely because its current appearance happens to match. Search the actual definitions and references before treating a variable as a sitewide control.
Scope values where they belong
Double-dash custom properties inherit by default. A value on the root can therefore reach descendants, while a declaration within a component can change the value in that scope. Normal cascade rules still determine which applicable declaration wins.
.compact-section {
--card-space: 0.75rem;
}
A service card inside that section can receive the smaller spacing through inheritance. A card elsewhere can retain the root value. This is useful when the exception is intentional and documented.
Check nested components before changing a broad definition. If a value is registered with @property, its defined type, initial value and inheritance setting add further rules to inspect.
Understand what a fallback does
The fallback in var(--card-space, 1rem) helps when the referenced custom property is unavailable in the relevant way. It does not make unsupported custom-property syntax work in an older browser.
It also does not validate every possible value for the consuming property. If a custom property exists but contains something that cannot be used as padding, the resulting declaration can become invalid. Inspect the computed padding rather than assuming the fallback supplied a valid size.
Test a change through its consumers
- List the definition and every relevant reference.
- Record local overrides and deliberate fixed values.
- Change the value in development.
- Inspect representative components and responsive states.
- Verify the computed result when a component behaves differently.
For an illustrative color example, a button and a banner might both use one accent variable. Changing it can affect different foreground/background pairs. A shared token reduces repetition; each resulting color combination still needs review.
The relative-color guide explains derived color dependencies. The CSS unit guide explains the reference behind spacing and sizing values.
Keep CSS values and builder features distinct
A builder may expose reusable colors, text or images through its own controls. Verify how those controls store and apply values rather than assuming every builder variable is a CSS custom property or that it reaches every page.
For an existing-site change, identify the source of the value, the intended consumers and the exceptions. Keep the definitions with the project’s maintained styles so the next developer can find them.
Key Takeaways
- Custom properties require explicit references to affect a declaration.
- Scope, inheritance and the cascade determine the effective value.
- A var() fallback is not universal validation or browser compatibility.
- Test consumers and exceptions after changing a shared value.
Frequently Asked Questions
Does a root variable replace every matching value?
No. A declaration must reference it, directly or through another value. Visually similar hard-coded values can remain unchanged.
Can a component override a shared variable?
Yes. Inspect its scope, inheritance and applicable cascade rules to determine the effective value.
Will var() always use its fallback when a value is unsuitable?
No. An existing custom-property value can make the consuming declaration invalid without selecting the fallback. Check the actual computed result.

