How to nest with intention,
avoid brittle hierarchies,
and guide AI through complex shapes
—Part of CSS Primer for the AI Era — Structure
Nesting is natural.
Interfaces are made of parts inside parts —
cards inside lists,
buttons inside toolbars,
fields inside forms.
But nesting can also create:
The mental model:
Nest for meaning,
not for convenience.
This page explores when nesting strengthens structure,
when it weakens it,
and how to guide AI through nested components
without creating fragility.
Nesting is helpful when it expresses real relationships.
a)- A component inside another component
Examples:
card inside a listnav_item inside a nav_listorm-field inside a formThis expresses meaning:
b)- When the parent gives context
Examples:
The parent defines the purpose.
The children inherit that purpose.
c)- When the structure is stable
Nesting helps when:
A quiet principle:
Nest when
the relationship is meaningful
and
unlikely to change.
Nesting becomes harmful when it creates accidental dependencies.
a)- Too much depth
Deep nesting leads to:
Example of harmful depth:
.nav > ul > li > a > span > strong { ... }
This is not structure — it is a trap.
b)- Nesting for layout instead of meaning
Example:
<div class="card"> <div class="grid"> <div class="card__header">...</div> </div> </div>
Here, layout is dictating structure.
This makes the component brittle and inflexible.
c)- Nesting components that should be siblings
Example:
<div class="card"> <div class="button">...</div> </div>
If the button is conceptually separate,
nesting it inside the card creates unnecessary coupling.
d)- Nesting that forces CSS to become overly specific
When structure is unclear, CSS compensates with:
!importantA quiet truth:
If CSS feels difficult,
the structure is probably unclear.
Nesting directly shapes how CSS behaves.
Helpful nesting leads to:
Harmful nesting leads to:
Nesting is not just HTML structure —
it is CSS architecture.
AI does not infer structure.
It only sees what you show it.
Clear nesting helps AI:
Harmful nesting confuses AI:
A quiet reminder:
AI follows the structure you give it —
even when the structure is accidental.
A few calm rules:
Rule 1
— Nest only when the parent gives meaning
Rule 2
— Keep depth shallow
Rule 3
— Avoid layout‑driven nesting
Rule 4
— Keep components portable
Rule 5
— Use naming to clarify boundaries
Rule 6
— Avoid selectors that depend on deep structure
A simple principle:
Nesting should express meaning,
not enforce styling.
Flattening helps when:
Example of flattening:
Instead of:
<div class="card"> <div class="card__header"> <div class="button">...</div> </div> </div>
Use:
<div class="card"> <div class="card__header">...</div> </div> <div class="button">...</div>
Flattening restores clarity.
Nesting is powerful when used intentionally.
It expresses relationships, clarifies structure,
and supports style.
But nesting can also create fragility when it becomes:
A quiet closing thought:
Nest when it clarifies the story.
Flatten when it restores freedom.
And let structure guide style,
not the other way around.
Tony de Araujo —New York | Lisbon