Inheritance and invalid value behavior
Definition and purpose
The cascade can choose a declaration that becomes invalid only after substitution. For an ordinary property, this produces the effect of unset: an inherited property inherits and a non-inherited property uses its initial value. The browser does not restart the cascade to recover an earlier declaration.
Late invalid color
<!doctype html><html lang="en"> <head> <meta charset="utf-8"> <meta name="viewport" content="width=device-width, initial-scale=1"> <title>CSS practice</title> <style> body { margin: 0; font: 16px sans-serif; color: #172033; background: white; } #parent { color: green; --tone: 20px; } #a { color: blue; color: var(--tone, red); } </style> </head> <body> <section id="parent"> <p id="a">Message</p> <p id="b">Detail</p> </section> </body></html>The winning declaration fails after substitution. Green is inherited, not blue or red.
Syntax and mental model
Unregistered custom properties accept token sequences, so --tone: 20px is not itself invalid. Substituting it into color is invalid, and the fallback in var(--tone, red) is not consulted. A cycle such as --a: var(--b); --b: var(--a) on the same element instead makes the cyclic custom properties guaranteed-invalid. References to them can use a fallback.
Cycle with fallback
<!doctype html><html lang="en"> <head> <meta charset="utf-8"> <meta name="viewport" content="width=device-width, initial-scale=1"> <title>CSS practice</title> <style> body { margin: 0; font: 16px sans-serif; color: #172033; background: white; } #parent { --a: var(--b); --b: var(--a); } #a { color: var(--a, navy); } </style> </head> <body> <section id="parent"> <p id="a">Message</p> <p id="b">Detail</p> </section> </body></html>The cycle makes the reference invalid; the fallback is navy.
Common mistakes
Do not assume that var() fallback catches every invalid color or length. Also, an inherited computed custom property has already resolved its references on the parent; changing one of those dependencies on a child does not recompute that inherited token.
Practice and next steps
After trying the examples, complete the linked coding exercise and review questions. Predict the result before running your code. Prerequisite: Custom properties and var. Next lesson: Registered custom properties.
Check Your Understanding
Solidify your learning with the interactive assessment directly below this lesson.
Concept Quiz & Questions
Inheritance and invalid value behavior — knowledge check
Five questions on inheritance and invalid value behavior.
If a defined --tone is 20px, what happens in color: var(--tone, red)?
For invalid computed color, what is the default effect?
What does a same-element custom-property cycle cause?
Can var(--a, navy) use navy when --a is cyclic?
When is an inherited alias resolved?