liveBook · Manning

Cascade

As explained in D3.js in Action, Third Edition

The CSS cascade is the algorithm that resolves competing declarations by considering their origin, importance, specificity, and source order.

The CSS cascade resolves competing declarations by weighing their origin, importance, specificity, and source order. For SVG, styles can come from attributes, inline styles, or external stylesheets. section 2.6 section 1.2.4

When the same SVG property is declared in several places:

  • An inline style overrides the same property from an external stylesheet. section 2.6 section 1.2.4
  • An external stylesheet declaration overrides the corresponding presentation attribute. section 2.6
  • Separating JavaScript behavior from CSS presentation makes large projects easier to maintain and keeps styling architecture deliberate. section 1.2.4

Three competing fills

A rectangle receives fill="turquoise" as an attribute, style("fill", "plum") as an inline style, and fill: orange from main.css. The visible result is plum because the inline declaration wins. section 2.6

How D3.js in Action, Third Edition covers it

How deep it goes
Demonstrates precedence with a three-way SVG fill example but does not work through the full cascade algorithm.
Examples
Uses a D3 rectangle with turquoise, plum, and orange fill declarations to make precedence visible.
What it assumes
Assumes basic CSS and DOM familiarity while demonstrating SVG attributes, inline styles, and external stylesheet rules.
What you can do after
Apply it via D3 and CSS to choose predictable styling sources and diagnose which declaration controls an SVG property.
How it connects
Connects CSS to SVG attributes, inline styles, external stylesheets, JavaScript, and separation of concerns.

Also explained in

Compare how 5 books explain cascade →

Related concepts

This explainer was generated by Manning's knowledge graph from the text of D3.js in Action, Third Edition. The section links point to the parts of the book it draws on.