How do custom properties inherit, and when does @property change that behavior?
Quick answer
An unregistered --name custom property inherits from its parent unless another declaration overrides it. Registering a property with @property lets you specify whether it inherits, what value types it accepts, and its initial value. Use registration when those rules are useful; otherwise, ordinary inheritance is often enough. Registration does not guarantee identical browser support everywhere.
The question, the details, the next step.
A practical checklist
Identify the element where the custom property is declared and trace its descendants.
Check whether an unregistered property is overridden on the element or an ancestor branch.
For
@property, specify bothsyntaxandinherits.Provide an appropriate
initial-valuefor non-universal syntax; make it computationally independent.Test a child with no declaration and one with an override in relevant browsers.
A few more useful answers
Does `inherits: false` mean the property has no value on a child?
No. It means the registered property does not inherit from its parent. The registered initial value can apply when the child has no value of its own.
Can I omit `initial-value` from every registration?
No. It may be omitted only with universal syntax (*). Otherwise, it is required and must be computationally independent. [S2]
Does `@property` guarantee the same behavior in every browser?
No such guarantee is established here. Check support in the browsers relevant to your project before depending on registration.
Sources
References used for this guide.
- [S1] Using CSS custom properties — MDN developer.mozilla.org · Checked
- [S2] Registering custom properties in CSS — MDN developer.mozilla.org · Checked
