Why does a later CSS rule lose even though it appears last?
Quick answer
A later rule does not automatically win: the cascade considers origin and importance before specificity, and declarations are compared within the relevant cascade context. Normal unlayered author styles also outrank normal layered author styles. If competing declarations remain tied, later steps such as scoping proximity and source order can decide the result. Inspect the matched declarations in your browser’s Styles panel instead of guessing from file order. [S1][S2]
The question, the details, the next step.
A practical checklist
Select the affected element and name the exact property that is wrong.
Find the active and crossed-out matching declarations in the Styles panel.
Check origin and importance before comparing specificity.
Check layer context, including whether a normal author declaration is unlayered.
Compare specificity in the relevant cascade context, then consider later tie-breakers.
Make one focused edit and confirm the winning declaration in the panel.
A few more useful answers
Does moving a rule to the bottom of the stylesheet ever help?
It can help when competing declarations are otherwise tied at the cascade steps that matter. It will not by itself overcome an earlier precedence difference. [S1]
Why are some matching declarations crossed out in developer tools?
The Styles panel can show declarations that matched but lost because of cascade, specificity, or source order. Use the active declaration and crossed-out rules to investigate the conflict. [S2]
Does a more specific selector always win?
No. Origin and importance are considered before specificity, and specificity is compared among declarations in the origin and layer that has precedence. [S1]
Sources
References used for this guide.
- [S1] Specificity — MDN developer.mozilla.org · Checked
- [S2] Cascade layers — MDN Learn web development developer.mozilla.org · Checked
