Master

A stylesheet that survives change

A stylesheet that works is not finished. The next design change, the next content, and the next person all have to edit it without breaking what works. The structure that makes that possible is the same structure that makes code reviewable: small named pieces, one place per decision.

What you will see

The row owns the gap and the card owns only its inside. The same card now works in any container, which is the point.

About 1 min of reading

Try It

Pull spacing out of a component.

1

Before

.card { margin: 16px; padding: 12px; }

Before you run it, say out loud what it will print. Then open the answer.

What it prints
The card brings its own outer spacing, so it cannot sit in a row without extra rules undoing that margin.
2

After

.card { padding: 12px; } .list { display: flex; gap: 16px; }

Before you run it, say out loud what it will print. Then open the answer.

What it prints
The row owns the gap and the card owns only its inside. The same card now works in any container, which is the point.

Data Flow

Tokens, components, and containers compose.
1 Define the tokens once
↓
2 Write components that read them
↓
3 Let containers place the components
↓
4 Order the file by the reading order
Why this works
Delete the duplication you find

Two rules that set the same four properties for different reasons are a bug waiting to drift apart. Merge them into one component class and the drift becomes impossible.

Leave the file readable to a newcomer

Sections named after what they style, in the order the page reads them. A newcomer can find the rule for a thing in thirty seconds, which is the bar for a stylesheet anyone else will ever edit.

Examples

Components, not pages

Style a card once and it works in the toolbar, the list, and the search result. A stylesheet written per page has three versions of the same thing, and the next change has to find all three.

Tokens at the top

Colours, spacing, and type sizes as named values in one block. Every rule reads the names, so a design change is one edit and a search for the old value is unnecessary.

Layout owned by the container

Let the parent place its children and let components bring no outer margin. Then a component can move anywhere without dragging spacing, which is the difference between a layout that composes and one that does not.

Words this lesson uses

Each one is defined here on this site. Open the entry for the full definition and the other words it points at.

← Markup that serves everyone
Previous Lesson
Markup that serves everyone
Next Lesson
Reading what a page actually did
Reading what a page actually did →