CSS cascade

The CSS process that decides which of several competing rules sets a property on an element.

In more detail

The browser compares where each rule comes from, its specificity and its order in the stylesheets; the order of class names in the HTML class attribute plays no part. Separately, some properties, including custom properties, are inherited from parent to child elements. Together these let a theme set on one element flow down to everything inside it.

Example

In the browser: It compares, in order: origin and importance, then cascade layer, then specificity, then source order. The first step that finds a difference decides the winner, so specificity only matters when origin and layer are equal.

Related terms

Taught in

References