Preparing your workspace
The cascade, specificity, source order, and inheritance determine which CSS declarations are applied.
Large CSS projects often contain multiple rules that could apply to the same element. The cascade is the browser's process for deciding which declarations win. Specificity gives different weights to selectors. In general, an ID selector has more specificity than a class selector, which has more specificity than an element selector. When specificity is equal, later rules normally win. Some properties inherit from parent elements, while others do not. Understanding these rules helps developers solve styling conflicts without blindly adding !important.
A shared button class may set a default text color while a more specific state or component rule changes that color for a particular situation.
button {
color: black;
}
.button {
color: blue;
}
#save-button {
color: green;
}The button with the matching ID selector receives the green color because the ID selector has greater specificity.