CSS Primer For the AI Era

A vocabulary for shaping interfaces with AI

User Tools

Site Tools


foundations:css_cascade_for_the_ai_era

2- The Cascade — How CSS Decides

— the quiet algorithm behind every style

CSS looks simple on the surface:
we write a rule,
the browser applies it.

But underneath that simplicity
is a small, steady →decision‑making process
called the 'cascade'.

The cascade is how CSS →answers the following question:

“When multiple rules
want to style the 'same thing',
which rule
should CSS listen to?”

— Everything in CSS flows from this question.

Nowadays, we don’t need to memorize the algorithm.
We just need to understand the forces that…
shape 'that' answer.
—which rule should CSS listen to?—


1. The Cascade Is a Referee

When two or more rules apply to the same element,
CSS evaluates them in a specific order:

  1. Where the rule came from
    (browser → user → author → important)
  2. How specific the selector is
    (element < class < id < inline < important)
  3. Which rule appears last
    (later wins over earlier)

That’s it.

Three quiet forces
deciding which instruction wins.

This is why AI sometimes
generates CSS that “does nothing
—the cascade silently overrides it
.

Once we understand this,
we can guide AI:

“Increase specificity.”
“Avoid using IDs.”
“Make this rule win without using !important.”
 “Place this rule after the others.”

We’re not memorizing syntax
— we’re shaping intention.


2. Why It’s Called a Cascade

CSS is literally named after this idea:
Cascading Style Sheets.

Styles flow downward, like water:

  • from the browser’s defaults
  • to the user’s preferences
  • to our local stylesheet
  • to the last rule that applies
    probably in the HTML code itself.

Each layer can override the one above it.

This is why the cascade feels natural once we see it
— it behaves like gravity.


3. The Waterfall Analogy

Let's imagine a waterfall
with several tiers
.

At the top:
— the browser’s default styles.

Below that:
user styles (like accessibility settings).

Below that:
our styles.

At the bottom:
— the last rule we wrote.

Water flows downward. So do styles.

If two streams collide, the one lower in the waterfall wins —
unless a higher stream has more force (specificity).

This analogy is enough
to understand 90% of CSS behavior
.


4. The Cascade Is Not About Memorization

We don’t need to remember:

  • the exact specificity formula
  • the order of origins
  • the weight of inline styles
  • the details of !important

We only need to remember the shape:

Origin → Specificity → Order

Whenever something “doesn’t work,”
one of these three forces is deciding against us.

And once we know that, we can ask AI:

“Why is this rule losing the cascade?”
“Which selector is more specific?”
“Rewrite this rule so it wins without !important.”

We’re not fighting CSS — we’re collaborating with it.


5. The Cascade Is the First Force of CSS

We've already introduced the five forces:

  • cascade
  • specificity
  • inheritance
  • flow
  • context

The cascade is the first because it’s the referee.
It decides which rule even gets a chance to apply.

Everything else
— layout, inheritance, context —
only matters after the cascade chooses the winning rule.

This is why understanding the cascade
is the first step
to writing CSS with confidence
and guiding AI with clarity
.


6. The Mental Model in One Sentence

CSS is always deciding which instruction to listen to.
The cascade is how it makes that decision.

Once we see this, CSS stops feeling random.
It becomes a conversation we can participate in —
and guide AI through — with calm and intention.



Tony de Araujo —New York | Lisbon


foundations/css_cascade_for_the_ai_era.txt · Last modified: by editor