The CSS cascade selects a winning declaration for each property on each element from the declarations that apply. Its ordering includes origin and importance, CSS cascade layers, CSS specificity and source order. Later comparisons settle ties left by earlier priorities; a rule's position at the end of a file is therefore only one part of the decision.[ref]
CSS Cascading and Inheritance Level 5 by World Wide Web Consortium. §6, Cascading, and Cascade Sorting Order
Suppose a paragraph has
class="warning", and two ordinary, unlayered author rules are .warning { color: red; } followed by p { color: blue; }. Both match, but the class selector has greater CSS specificity, so red wins despite the blue rule's later position. If the second rule is p { color: blue !important; }, its importance instead makes blue win over the normal red declaration. These examples hold other styling inputs fixed.Origins represent different participants, including the browser's default rules, the user and the page author. For example, important user declarations outrank important author declarations, allowing user styling to take priority in that part of the system. Layer order is also a separate input; adding selectors with larger specificity is not a substitute for understanding that earlier comparison.[ref]
CSS Cascading and Inheritance Level 5 by World Wide Web Consortium. §6.2, Cascading Origins; §6.4, Cascade Layers; origin/importance sorting
CSS inheritance addresses a different question: how a property receives a value from the parent when the property's defaulting rules call for inheritance. A parent being red does not create a competing selector match on every descendant. Keeping applicability, cascade selection and inheritance distinct explains why an element can inherit a color even though no rule explicitly selects that element.
Articles by others on the same topic
There are currently no matching articles.