The Entire Cascade

When multiple styles apply to the same property (e.g. color ) on the same element (e.g. one specific button ), the cascade is used to determine which style has priority.

While we often refer to that as specificity in conversation, that term actually refers to one small step of the process. The overall priority of a declaration is called its Cascade Precedence . But those two are directly related – one being a subset of the other. Selectors with higher specificity also have a higher cascade precedence.

For every set of styles declared on the same property of the same element, we start at the top of the cascade process. At each step, we group the styles into categories. The top category with styles in it is the only category that moves on to the next step. Any other styles can be eliminated from consideration.

In the first step, we separate out normal styles from ❗️important styles – and for most of the way down, we only need to look at one side or the other. It's like a single-elimination bracket, only one style can win it all!

  1. Origin & Importance

    Who applied the style, and how important is it?

    1. CSS Transitions
    2. ❗️User Agent (Browser)
    3. ❗️User (Preferences)
    4. ❗️Author (Site)
    5. CSS Animations
    6. Author (Site)
    7. User (Preferences)
    8. User Agent (Browser)
  2. (Shadow) Context

    Is it coming from the main document, or embedded shadow DOM?

    important
    1. ❗️Shadow DOM
    2. ❗️Host (Light) DOM
    normal
    1. Host (Light) DOM
    2. Shadow DOM
  3. Element-Attached Styles

    Separately for normal and important styles, inline styles win over selectors.

    important
    1. ❗️Inline Styles
    2. ❗️Selectors
    normal
    1. Inline Styles
    2. Selectors
  4. Cascade Layers (new!)

    Layers stack in the order they are declared, with the first layer having lowest priority, building to the last layer, and then un-layered styles. The order is reversed for important styles.

    important
    1. ❗️ First-Layer
    2. ❗️
    3. ❗️ Last-Layer
    4. ❗️ Un-Layered Styles
    normal
    1. Un-Layered Styles
    2. Last-Layer
    3. First-Layer
  5. Selector Specificity

    The selector with the most IDs wins. If there is a tie for the most IDs, repeat the process for each selector type.

    1. #id
    2. .class | :pseudo-class | [attribute]
    3. element | ::pseudo-element
    4. * | :where()
  6. Order of Appearance

    Last style wins!

For properties without any valid style at the end of the cascade, we have to move beyond the cascade. Inheritance (looking at parent values) and then Defaulting (using the initial value) fill in any remaining gaps.