Cascade, Specificity, and Inheritance
Predict which declaration wins instead of fighting the cascade with increasingly strong selectors.
The cascade resolves competing declarations using origin, importance, layer, specificity, and source order. Inheritance then carries selected properties, such as color and font, from parent to child. A clear layer order is more maintainable than scattered !important flags.
See the core pattern
Read this rule set from the outside in. Identify the inputs, the decision or transformation, and the result before changing it.
@layer reset, base, components, utilities;
@layer base {
a { color: #617713; }
}
@layer components {
.button { color: #10231f; }
}
@layer utilities {
.muted { color: #64716d; }
}Working rules
- Inspect the computed style before adding an override
- Keep selector specificity deliberately low
- Define cascade layers from broad defaults to narrow utilities
A common mistake
Using !important as a default escape hatch hides the real ordering problem and makes later changes expensive.
Guided practice
Explain why a class selector normally overrides a type selector in the same origin and layer.
- Copy the example into the editable notebook below.
- Change one thing at a time and keep the program or rule valid.