Table of Contents

01. Selectors — How We Point to What We Mean

—Part of CSS Primer for the AI Era — Selectors

Selectors are the language we use to point at elements in the document.

If HTML expresses meaning,
and CSS expresses appearance,
→ selectors are the bridge between the two.

Selectors answer a simple question:

In the AI era, selectors are not just a technical tool —
they are also a communication tool.
They give us the vocabulary to tell AI exactly what we want,
without ambiguity or guesswork.

Selectors are where CSS
becomes practical
.


1. What a Selector Really Is

A selector is a pattern
that matches elements
in the 'document tree'.

It doesn’t change anything by itself.
It simply identifies the elements we want to style.

Examples:

Selectors are the vocabulary of CSS.
They let us speak precisely
.

AI‑steering cue:

“Target only the direct children of this list 
using a child selector.”

2. Why Selectors Matter in the AI Era

Selectors give us a precise way to talk about which elements we mean.
Without selectors, CSS would have no way to connect 'style' to 'structure'.

In the AI era, this becomes even more important.

AI can generate CSS, but it often:

When we understand selectors,
we can guide AI with clarity
instead of trial and error.

Examples of practical guidance:

“Use a class selector instead of an ID.”
“Don’t target all paragraphs — only the ones inside the article.”
“Avoid long chained selectors; they’re brittle.”
“Use a child selector, not a descendant selector.”
“Select only the active link using a pseudo‑class.”

These are small phrases,
but they give AI the direction it needs.

Selectors become a shared vocabulary —
a way to express intent without writing the CSS ourselves
.

Why would selectors matter for modern communication?

Even if someone never writes CSS by hand,
knowing selector vocabulary lets them:

Selectors are the first place where
CSS becomes practical.

AI‑steering cue:

“Use a class selector to target these elements 
instead of relying on the HTML structure.”

3. The Three Levels of Selector Thinking

Selectors can feel endless when you look at a full reference sheet.
But in practice, almost everything we do falls into three levels.

These levels give us a simple mental map —
a way to understand the whole system without memorizing it.

Level 1 — Basic Selectors

These are the selectors we use most often:

They answer the question:

“What kind of element is this?”

This level is enough for 80% of everyday CSS.
It’s also the level AI overuses — especially IDs —
so knowing this vocabulary helps us guide it.

AI‑steering cue:

“Use a class selector instead of an ID 
— keep specificity light.”

Level 2 — Combinators (Relationships)

Combinators describe how elements relate to each other in the DOM.

Examples:

These selectors answer:

“Where is this element in relation to others?”

This level is where CSS becomes expressive.
It lets us target structure without adding extra classes.

AI‑steering cue:

“Use a child combinator 
— I only want direct children, not all descendants.”

Level 3 — Attribute, State, and Pseudo Selectors

These selectors target elements based on:

They answer:

“What condition is this element in?”

This level is where CSS becomes powerful and precise.
It lets us style:

AI often forgets these exist,
so knowing them helps us request cleaner,
more semantic solutions.

AI‑steering cue:

“Use a pseudo‑class to target the active link 
instead of adding another class.”

Why these three levels matter

This structure gives newcomers a sense of completion:

They don’t need to memorize the entire CSS spec.
They just need to know which kind of selector to ask for.

This is the vocabulary
that makes AI collaboration feel grounded
.


4. Selectors Are About Meaning, Not Just Structure

Selectors don’t just point at elements.
They express what those elements are in the context of the document.

Two selectors can match the same element
but communicate completely different intentions.

Examples:

Meaning matters because
CSS is not only about what we select —
it’s also about why we select it
.

Why this matters to us?

When someone says:

When AI sees:

Those are not the same thing.

Selectors let us choose the version that reflects intent.

Meaning makes CSS more stable

When we select based on meaning:

When we select based only on structure:

Meaning is the anchor that keeps CSS calm.

Meaning helps AI understand what we want

AI often defaults to structural selectors
because it sees the DOM as a tree of nodes.

But humans see the document as a set of roles:

When we use selectors that reflect meaning,
we guide AI toward better patterns.

Examples of meaningful guidance:

“Use nav a — these are navigation links.”
“Use .button — this is an action, not a heading.”
“Use section > h2 — these are section headings.”
“Use [aria-current="page"] — this is the active link.”

These small phrases help AI understand the intent behind the structure.

AI‑steering cue:

“Use a selector that reflects meaning, not just structure.”

5. Specificity — The Weight Behind a Selector

Every selector has a weight.
This weight determines which rule “wins”
when two rules try to style the same element.

Specificity is not about power.
It’s about priority.

The browser asks:

The louder selector wins.

The intuitive hierarchy

We don’t need to memorize numbers.
Just remember the shape of the system:

This is enough to understand 95% of specificity issues.

Why this matters?

AI often generates selectors that are:

When we understand specificity,
we can guide AI gently:

“Use a class instead of an ID.”
“Avoid chaining selectors — it increases specificity.”
“Don’t use !important — fix the selector instead.”
“Keep specificity light so future changes are easier.”

These small phrases help AI produce CSS that is stable and maintainable.

A few practical examples

→ quiet selector. A class can override it:

p { color: blue; }

→ louder (class + element). This wins over the plain p selector:

.article-text p { color: black; }

→ very loud (ID + element). This wins over both previous rules:

#main p { color: green; }

→ breaks the system. This wins over everything — even IDs:

p { color: red !important; }

Why we avoid heavy selectors

Heavy selectors:

Light selectors keep CSS flexible.

Specificity is a conversation

When we choose a selector, we’re not just pointing at an element.
We’re deciding how loudly we want to speak.

Sometimes we whisper.
Sometimes we speak clearly.
We almost never shout.

AI‑steering cue:

“Keep specificity light — 
use a class selector instead of an ID.”

6. Selectors Are a Conversation with the DOM

Selectors don’t operate on the HTML file itself.
They operate on the DOM
— the tree the browser constructs from the file.

This means a selector is never evaluated in isolation.
It is always evaluated in context.

When we write a selector, we’re really saying:

“In this tree, find the elements that match this pattern.”

Why this matters

The DOM is not just a list of elements.
It is a structure:

Selectors speak the language of that structure.

A few quiet examples:

Each selector expresses a relationship in the tree.

Why this matters for us:

When people first learn CSS,
they often think selectors are “commands.”
But selectors don’t command anything.
They ask the DOM a question:

“Do you have any paragraphs?”
“Do you have any links inside navigation?”
“Do you have any list items directly under this list?”
“Do you have any elements with this class?”

The DOM answers by returning the matching elements.

CSS then applies the styles.

Understanding this makes CSS feel less magical
and more predictable.

Why this matters for AI:

AI sees the DOM as a tree of nodes.
Humans see it as a document with meaning.

When we use selectors that reflect the DOM’s structure,
we help AI understand the relationships we care about.

Examples of helpful guidance:

“Select only the links inside this section.”
“Don’t target all list items — only the direct children.”
“Use a descendant selector; the structure may change.”
“Avoid chaining too many selectors — it makes the DOM relationship brittle.”

These small phrases help AI generate CSS that respects the tree.


The mental model

Selectors are not instructions.
They are queries.

They ask the DOM to find elements that match a pattern. T
he DOM responds.
CSS applies styles to the result.

This is the quiet conversation happening behind every rule.

AI‑steering cue:

“Explain how this selector interacts with the DOM structure 
before generating the CSS.”

7. What Readers Will Learn in This Topic

This topic gives us a practical vocabulary —
just enough to understand how CSS selects elements,
and enough to communicate clearly with AI.

Even if we never write CSS by hand,
we’ll finish this topic with a sense of fluency.

Readers will learn how to:

Why this matters

Selectors are the first place where CSS becomes practical.
They give readers the vocabulary to:

This topic is designed to give us a sense of completion —
a feeling that they’ve learned something real,
something they can use immediately.

AI‑steering cue:

“Use a selector that expresses intent 
— not just structure.”

8. The Mental Model to Carry Forward

Selectors are not about memorizing syntax.
They are about expressing intent.

When we choose a selector,
we’re really answering three quiet questions:

  1. What is this element?
    (its role, its meaning)
  2. Where does it live in the document?
    (its relationships, its context)
  3. What condition is it in?
    (its state, its attributes)

This is the mental model that
makes selectors feel natural instead of technical.

Selectors express meaning
A selector is not just a pointer.
It’s a statement of purpose:

“These are navigation links.”
“These are buttons.”
“These are warnings.”
“These are list items inside this section.”

When we express meaning, our CSS becomes clearer —
and AI understands our intentions more easily.

Selectors express relationships
The DOM is a tree,
and selectors describe how elements relate:

These relationships matter more than the tags themselves.

Selectors express conditions
Selectors can also describe:

These conditions let us target behavior,
not just structure.

Why this mental model matters When readers carry this model forward, they can:

Selectors become a language they can speak —
a way to communicate clearly
with both the browser and AI.

AI‑steering cue:

“Choose a selector that reflects what this element is, 
where it lives, and what state it’s in.”

Tony de Araujo —New York | Lisbon