According to how CSS works, cascading is the key concept of CSS, which allows several style sheets to influence the presentation of a document.
The cascade algorithm takes an unordered list of declared values for a given property on a given element, sorts them by their declaration’s precedence as determined below, in descending order of priority, and outputs a single cascaded value.
When the cascade does not result in a value, the specified value must be found some other way. Inherited properties draw their defaults from their parent element through inheritance; all other properties take their initial value. Authors can explicitly request inheritance or initialization via the
Based on combination of declaration origins (user agent, user, author, transition, animation) and
!important annotation. The precedence of the various origins is, in descending order:
1. Transition 2. User agent + `!important` 3. User + `!important` 4. Author + `!important` 5. Animation 6. Author 7. User 8. User agent
!important: An important declaration takes precedence over a normal declaration. Author, user, and user-agent style sheets may contain important declarations.
A weight that is applied to a given CSS declaration, determined by the number of each selector type in the matching selector, highest specificity wins.
The resulting specificity is not a number but a tuple of numbers like
(a,b,c). Read how to calculate CSS specificity for more details.
The last declaration in document wins in case of equal specificity.