liveBook · Manning

Cascade

As explained in Web Design Playground

The CSS conflict-resolution mechanism that determines which style rule applies when multiple style sources overlap.

The CSS cascade decides which style declaration wins when several styles overlap. Think of styles as taking different routes toward an element: browser defaults, user preferences, and your own styles all meet, and the browser resolves the conflict. section 1.4 section 19.26

Follow the cascade in two small steps:

  • Compare the style sources. In ascending order of weight, they are browser default styles, user custom styles, external style sheets, internal style sheets, and inline styles. Declarations closer to the element generally carry more weight. section 19.26 section 19.30
  • If competing declarations come from the same source, compare selector specificity: elements and pseudo-elements, classes and pseudo-classes, IDs, inline styles, and finally the !important keyword. section 19.30

A tiny color clash

An internal rule sets div text to red, while the element itself has an inline style setting its text to blue. The inline declaration wins because it comes from the higher-weight source, so the text appears blue. section 19.26

<style>    #1  
    div {    #1  
        color: red;    #1  
    }    #1  
</style>    #1  
<div style="color: blue;">    #2  
    What is the color of this text?
</div>

Inspect the competing declarations and predict the rendered color before checking the cascade’s result. section 19.26

Inheritance explains what styles are passed from parents to descendants; the cascade explains how overlapping declarations are prioritized. Together, they help make CSS conflicts feel less mysterious. section 19.26 section 19.30

How Web Design Playground covers it

How deep it goes
Explains source priority and same-source specificity with a concrete conflict, rather than detailing the complete browser algorithm.
Examples
Uses a div with red internal styling and blue inline styling to demonstrate which declaration wins.
What it assumes
Assumes basic CSS rules and declarations while distinguishing cascade from inheritance.
What you can do after
Diagnose CSS conflicts by comparing declaration sources and selector specificity.
How it connects
Connects CSS inheritance, specificity, inline styles, external style sheets, internal style sheets, and user agent styles.

Also explained in

Compare how 5 books explain cascade →

Related concepts

This explainer was generated by Manning's knowledge graph from the text of Web Design Playground. The section links point to the parts of the book it draws on.