Four Stages of the Cascade Algorithm
The cascade algorithm is split into 4 distinct stages.
- Position and order of appearance: the order of which your CSS rules appear
- Specificity: an algorithm which determines which CSS selector has the strongest match
- Origin: the order of when CSS appears and where it comes from, whether that is a browser style, CSS from a browser extension, or your authored CSS
- Importance: some CSS rules are weighted more heavily than others, especially with the !important rule type
Order of Specificity for Origins
- User agent base styles. These are the styles that your browser applies to HTML elements by default.
- Local user styles. These can come from the operating system level, such as a base font size, or a preference of reduced motion. They can also come from browser extensions, such as a browser extension that allows a user to write their own custom CSS for a webpage.
- Authored CSS. The CSS that you author.
- Authored !important. Any !important that you add to your authored declarations.
- Local user styles !important. Any !important that come from the operating system level, or browser extension level CSS.
- User agent !important. Any !important that are defined in the default CSS, provided by the browser.
Order of Importance
- normal rule type, such as font-size, background or color
- animation rule type
- !important rule type (following the same order as origin)
- transition rule type
Leave a Reply