Why does a CSS declaration appear in the stylesheet but not take effect?
Quick answer
A declaration can be visible in a stylesheet but have no effect if its property or value is invalid or unrecognized, its selector does not match, or its rule is inactive. Even a valid, applicable declaration can lose in the cascade. Inspect the rule and the element’s computed value in browser developer tools, then check each possibility. A custom property can also produce an invalid value after substitution. [S1] [S2]
The question, the details, the next step.
A practical checklist
Select the intended element in developer tools and confirm that the rule’s selector matches.
Check the property spelling, value syntax, and where the declaration sits in the rule.
Check whether the stylesheet or a condition containing the rule currently applies.
Look for other declarations of the same property and identify which one takes effect.
Inspect the computed value and, when using a custom property, trace the value used by
var().Change one thing at a time and recheck the rule and computed result.
A few more useful answers
Can a custom property cause a declaration to be invalid?
Yes. A declaration using a custom property can become invalid after the value is substituted, so check the value being substituted as well as the consuming declaration. [S1]
Does a different computed value always mean the declaration is invalid?
No. A declaration may be valid but not apply because its selector does not match or its rule is inactive, or it may lose in the cascade. Inspect the applicable rules as well as the computed value. [S2]
Sources
References used for this guide.
- [S1] CSS error handling — MDN developer.mozilla.org · Checked
- [S2] CSS property value processing — MDN developer.mozilla.org · Checked
