HTML & CSS Interview Question #59
What is the CSS cascade?
CSS Fundamentals, Selectors, Cascade, Specificity, Box Model, Units & Typography Mid-Level Intermediate
Quick Interview Answer
The cascade is the algorithm CSS uses to resolve competing declarations that apply to the same property on the same element. It considers factors including origin and importance, cascade layers, specificity, scoping proximity where applicable, and source order.
Detailed Explanation
The cascade is the algorithm CSS uses to resolve competing declarations that apply to the same property on the same element. It considers factors including origin and importance, cascade layers, specificity, scoping proximity where applicable, and source order.
The cascade is why CSS can combine browser defaults, author styles, component rules, and local overrides. Good CSS architecture works with the cascade instead of repeatedly fighting it with highly specific selectors or !important.
Code Example
p {
color: gray;
}
.article p {
color: navy;
}
/* The more applicable winning declaration
is determined by the cascade. */