Scale
A small set of spacing values used repeatedly.
Spacing systems turn layout from guesswork into rhythm. Instead of random margins and padding, you use a repeatable scale.
:root {
--space-4: 1rem;
--space-12: 3rem;
}
Layout
Spacing is one of the strongest signals of design quality. Too tight feels cramped. Too loose feels disconnected. Random spacing feels amateur.
A spacing system defines reusable values for padding, gaps, section rhythm and component relationships.
CSS custom properties make spacing scales easy to reuse across cards, layouts, buttons and page sections.
A small set of spacing values used repeatedly.
Container-owned spacing between flex or grid children.
Large vertical space between major content areas.
Inner space that belongs to a reusable component.
Visual model
Good layout CSS is not a pile of positions. It is a set of relationships: flow, axis, tracks, placement, layering, sticking and rhythm.
Tiny internal adjustments.
Default component gaps.
Cards and panels.
Section separation.
Examples
:root {
--space-2: .5rem;
--space-4: 1rem;
--space-6: 1.5rem;
--space-12: 3rem;
}
.card { padding: 23px; }
.grid { gap: 19px; }
.section { margin-top: 87px; }
.button { padding: 11px 27px; }
Rules that matter
Layout work is where real content, real devices and real users expose weak assumptions. The goal is a structure that explains itself in code and survives change.
Too many spacing tokens becomes another form of randomness.
Let flex and grid containers own repeated spacing.
Button padding and page section rhythm are different decisions.
margin-block and padding-inline describe intent clearly.
Similar relationships should use similar spacing.
Break the scale only when the design problem truly demands it.
Production thinking
Spacing is where many high-end designs get their calm. A spacing system makes that calm repeatable.
Clear spacing improves scanning, touch accuracy and form comprehension.
Define spacing tokens early and use them in components, layout utilities and sections.
Well-spaced content is easier to scan, which helps visitors understand and continue reading.
Live code lab
The preview runs in an isolated iframe. Links and forms stay inside the practice area, so you can experiment without leaving the lesson.
Mini assignment
Practice assignment
Try it yourself
Self-check
Answer these questions before moving on. If the answer is vague, change the lab layout and inspect the result.
Senior audit upgrade
A spacing system can use raw scale tokens and semantic tokens. The best choice depends on whether the value is general or tied to a component role.
--space-1, --space-2 and --space-3 are good reusable primitive tokens.
--section-gap or --card-padding explains intent when a value has a specific job.
Use gap for relationships inside flex and grid instead of child margin hacks.
Chapter project
Choose normal flow, flexbox, grid, positioning and spacing systems for the right layout job.
a dashboard band with header, cards, action row, sticky note and clean spacing
Which parts use normal flow, flexbox and grid, and why?