Sub topic 6
Place Sections on a Grid with a Spacing Scale
This chapter assumes you have a low-fidelity wireframe with ranked sections, and that you can use a design tool such as Figma. Basic HTML and CSS terms help but are not required. Here you turn the wireframe's boxes into aligned, evenly spaced sections.
Why a grid and a scale
A wireframe shows what goes where. It does not say how wide a block is, how far apart two blocks sit, or where their edges line up. Without rules, each of these becomes a one-off choice. The page then looks slightly off and nobody can say why.
Two tools remove most of those choices:
- A layout grid is a set of columns, gutters, and margins that every section snaps to.
- A spacing scale is a short list of allowed distances. You pick from the list instead of typing any number.
The grid controls horizontal placement. The spacing scale controls the gaps, mostly vertical, and the padding inside blocks. Together they make the design consistent, and they give a developer exact numbers to build from.
The parts of a column grid
A column grid has three measurements.
| Part | What it is | Typical desktop value |
|---|---|---|
| Columns | Vertical strips that content aligns to | 12 |
| Gutter | Empty space between two columns | 24 px |
| Margin | Space between the grid and the edge of the screen | 32 to 64 px |
Most homepages use 12 columns on desktop because 12 divides evenly into 2, 3, 4, and 6. A three-feature row takes 4 columns each. A half-and-half hero takes 6 and 6. A narrow text block can take 8 columns and sit off-center.
Tablet layouts often use 8 columns. Mobile layouts use 4. Fewer columns on small screens keep blocks wide enough to read.
Fixed width or fluid
Decide whether the grid has a maximum width.
- A fluid grid stretches columns as the window grows. It fills wide monitors but makes line lengths too long.
- A contained grid stops growing at a maximum width, often 1120 to 1280 px, and centers itself. Margins absorb the extra space.
For a homepage, a contained grid is the safer default. It keeps text lines readable and keeps the design predictable on large screens. Full-width backgrounds, such as a colored hero band, can still stretch edge to edge while the content inside stays on the contained grid.
Choosing a spacing scale
A spacing scale is a list of values that grow in steps. Many teams use a base unit of 8 px, and some use 4 px for finer control. Multiples of the base unit keep gaps in proportion.
A workable scale built on 8 px:
| Name | Value | Typical use |
|---|---|---|
| space-1 | 8 px | Gap between an icon and its label |
| space-2 | 16 px | Gap between a heading and its paragraph, inner padding of a button |
| space-3 | 24 px | Gutter, gap between cards |
| space-4 | 40 px | Padding inside a section on mobile |
| space-5 | 64 px | Padding inside a section on desktop |
| space-6 | 96 px | Gap between major bands, such as hero and features |
The values do not need to be perfectly regular. They should grow enough that two neighboring steps look different. If 16 px and 18 px are both allowed, nobody can tell them apart, and the scale has stopped doing its job.
Use space to show grouping
The main purpose of the scale is to express relationships. Things that belong together sit close. Things that are separate sit far apart. A heading should be nearer to its own paragraph than to the paragraph above it. If the gaps are equal, the reader has to work out the grouping from the words alone.
A useful rule: the space around a group should be larger than the space inside it. Inside a feature card use space-2. Between cards use space-3. Between the feature band and the next band use space-6.
How sections map to the grid
Take the wireframe's sections and give each a column span.
- Header. Logo spans 3 columns. Navigation spans the remaining 9 and aligns right.
- Hero. Headline and button span 6 columns on the left. The image spans 6 on the right. Or center a headline across 8 columns if there is no image.
- Features. Three cards of 4 columns each.
- Proof. A quote spans 8 columns, centered, with 2 columns of empty margin on each side.
- Footer. Four link groups of 3 columns each.
The diagram shows how one section is composed from the grid and the scale.
Turning the numbers into CSS
The mockup's numbers should match what the browser will do. The scale becomes custom properties, and the grid becomes a CSS Grid container. This sketch uses the 12-column, 24 px gutter layout described above.
:root {
--space-1: 0.5rem;
--space-2: 1rem;
--space-3: 1.5rem;
--space-4: 2.5rem;
--space-5: 4rem;
--space-6: 6rem;
--gutter: var(--space-3);
--page-max: 70rem;
}
.container {
max-width: var(--page-max);
margin-inline: auto;
padding-inline: var(--space-2);
}
.grid {
display: grid;
grid-template-columns: repeat(12, 1fr);
gap: var(--gutter);
}
.hero-text { grid-column: 1 / span 6; }
.hero-image { grid-column: 7 / span 6; }
.feature { grid-column: span 4; }
.quote { grid-column: 3 / span 8; }
.band {
padding-block: var(--space-5);
}Each rule maps to a decision in the design file. .hero-text starts at line 1 and spans 6 columns. .quote starts at line 3 and spans 8, which leaves 2 columns empty on each side. In CSS Grid, column lines are numbered from 1, so a 12-column grid has 13 lines.
Using rem units ties the spacing to the user's font size setting. At the default of 16 px, 1rem equals 16 px, so --space-2 matches the 16 px value in the design.
Edge cases and common errors
- Off-grid nudging. A designer moves a block 3 px to look right. The mockup looks fine, but the developer has no rule to build from. Fix the underlying issue, such as an image with uneven internal padding, instead of nudging.
- Gutters counted twice. A card width of 4 columns includes the gutters between those columns. Adding a gutter on top shifts everything right. Check that the right edge of the last card meets the right edge of the container.
- Margins that do not shrink. A 64 px margin works on desktop but leaves a 390 px phone with 262 px of content. Reduce the margin to 16 px on mobile.
- Too many scale values. If a design uses 9 different gaps, the scale is not being used. Remove values until each one has a clear job.
- Vertical rhythm ignored. Section padding that changes without reason makes the page feel uneven. Give every band the same padding unless there is a reason, such as a tighter band for a logo strip.
- Text blocks too wide. A paragraph spanning all 12 columns can reach 120 characters per line. Limit body text to about 8 columns, or about 45 to 75 characters per line.
A short checklist
Before you leave this step, check that:
- The grid has defined columns, gutter, and margin for desktop. Tablet and mobile values come in the responsive chapter.
- Every section has a column span written next to it.
- Every gap and padding value comes from the scale.
- The space around groups is larger than the space inside them.
- The body text width stays inside a readable line length.
The next chapters add type and color on top of this structure. Because the layout already follows rules, those later changes will not move your sections around.
Exercise
A 12-column grid has a 24 px gutter and a contained width of 1152 px with no side margins inside the container. A designer places three feature cards that each span 4 columns. What is the width of one card, and what is the width of one column? Explain why the card is wider than 4 times a column.
Show answer
Total gutter space is 11 gutters × 24 px = 264 px. Column space is 1152 − 264 = 888 px, so one column is 888 ÷ 12 = 74 px. A card spans 4 columns and 3 gutters inside it: 4 × 74 + 3 × 24 = 296 + 72 = 368 px. The card is wider than 4 × 74 = 296 px because it includes the 3 gutters between the columns it covers. Check: three cards of 368 px plus two 24 px gutters between them = 1104 + 48 = 1152 px, which fills the container.
Exercise
A feature card has a 16 px gap between its title and text, 24 px between the cards, and 24 px between the feature band and the proof band above it. What is wrong with this spacing, and what values from the scale in this chapter would you change it to?
Show answer
The gap between bands equals the gap between cards, so the reader cannot see that the bands are separate sections. The space around a group should be larger than the space inside it. Keep 16 px (space-2) inside the card and 24 px (space-3) between cards. Increase the gap between the bands to 96 px (space-6), or at least 64 px (space-5).