Table of Contents

02. Basic Selectors — Elements, Classes, and IDs

—Part of CSS Primer for the AI Era — Selectors

Basic selectors are the foundation of all CSS.
They are the simplest way to point at elements in the document,
and they form the vocabulary we use when guiding AI.

Even if someone never writes CSS by hand,
understanding these three selectors gives them enough fluency
to read AI‑generated code and request changes with more confidence.


1. Element Selectors — Targeting by Tag Name

Element selectors match all elements of a given type.

Examples:

Element selectors are broad.
They apply to every instance of that tag in the document.

When to use them

When to avoid them

AI‑steering cue:

“Use an element selector — 
I want all paragraphs styled the same way.”

2. Class Selectors — Targeting by Purpose

Class selectors match any element with a given class attribute.

Examples (given class names are aleatory:

Classes are reusable.
They are the most common and most flexible way to target elements.

Why classes matter:

Classes express purpose, not structure.

.button may describe “this behaves like a button

.active may describe “this is currently active

.highlight may describe “this needs emphasis

This makes class selectors ideal
for AI and human collaboration.

When to use them:

AI‑steering cue:

“Use a class selector — 
this is a role, not a unique element.”

3. ID Selectors — Targeting a Unique Element

ID selectors match exactly one element
— the one with that ID.

IDs must be unique in the document.
They are powerful, but they come with a cost: high specificity.

Why IDs are tricky:

Because IDs are so specific, they:

The safest rule is:

When to use them:

When to avoid them:

AI‑steering cue

“Avoid using an ID — 
it creates unnecessary specificity.”

4. How These Three Selectors Work Together

The following selectors form a natural hierarchy:

Most real‑world CSS uses:

This is also the pattern
we want AI to follow
.

A simple example:

p {
  line-height: 1.6;
}
 
.article-text p {
  max-width: 65ch;
}
 
.highlight {
  background: yellow;
}
 
#main-title {
  font-size: 2rem;
}

Each selector expresses a different kind of intent:

This layering is the heart of CSS.


5. The Mental Model

Think of basic selectors as three different ways of saying:

This could be all we need to feel fluent.

AI‑steering cue:

“Use a class selector instead of an ID — 
keep the rule flexible.”

Tony de Araujo —New York | Lisbon