Sub topic 4
Specifying layout, grid, and spacing
This chapter assumes you know how to build frames and auto layout in a design tool, and that you have read the chapter on design tokens. You also need a basic idea of how CSS lays out a page with margins, padding, and flexible widths. Spacing values here are tokens, so a spec can say "space-3" instead of "16px".
Why layout specs cause the most guessing
A developer can read a color from a swatch. Layout is harder, because the rules behind it are invisible. A screen shows that two cards sit side by side. It does not show whether they are fixed at 360px each or share the row equally. It also does not show whether the gap between them comes from the cards or from the container.
Your job is to state the rule, not only the result. A rule survives a longer headline or a narrower window. A measurement taken from one frame does not.
Describe the grid in terms of columns
Give the developer four numbers for each breakpoint: the number of columns, the gutter, the outer margin, and the maximum content width. The gutter is the space between columns. The margin is the space between the content and the edge of the window.
| Property | Desktop (1200px and up) | Tablet (768px to 1199px) | Mobile (below 768px) |
|---|---|---|---|
| Columns | 12 | 8 | 4 |
| Gutter | space-4 (24px) | space-3 (16px) | space-3 (16px) |
| Outer margin | space-5 (32px) | space-4 (24px) | space-3 (16px) |
| Max content width | 1140px | fluid | fluid |
State which columns are fixed and which are fluid. A typical statement is: "Columns stretch with the window. Content is centered once the window passes 1140px."
Use spacing from a scale
Every gap, padding, and margin should come from the spacing scale you defined in your tokens. If a frame uses 17px, that is almost always an error. Either round it to a token or add a new token on purpose.
Name the kind of spacing too. Padding is space inside a component. Margin and gap are space between components. Developers build these differently, so mixing them up leads to doubled or missing space.
.card-grid {
display: grid;
grid-template-columns: repeat(12, 1fr);
column-gap: var(--space-4);
max-width: 1140px;
margin-inline: auto;
padding-inline: var(--space-5);
}
.card {
grid-column: span 4;
padding: var(--space-3);
}The CSS above is a direct translation of the table. Three cards fit a row because each spans 4 of the 12 columns. If your spec is precise, a developer can write this without opening the design file.
Show how elements size themselves
For each element, say whether its size is fixed, fills the available space, or hugs its content. Design tools call these settings fixed, fill, and hug. Developers know the same ideas as a set width, 1fr or flex: 1, and auto.
Also record alignment and direction. "Horizontal stack, items centered vertically, gap space-2" is a complete description of a row. A screenshot with red measurement lines is not.
Handle content that changes length
Real content is rarely the same length as the mockup. Add a note for each place where text or images may vary:
- Titles that wrap to two or three lines: should cards stay equal height?
- Long words or email addresses: should they wrap, truncate with an ellipsis, or grow the container?
- Missing images: is there a fixed aspect ratio or a placeholder?
Answering these once in the spec saves a round of questions later.
Common errors
- Giving pixel positions measured from the top-left corner of a frame. Developers need relationships, such as "16px below the heading".
- Spacing the same gap twice, once as the top margin of one element and once as the bottom margin of the one above it.
- Using values outside the scale without saying why.
- Showing only the widest layout and leaving the grid for other breakpoints unstated.
Exercise
A card's frame uses 20px of padding, and the spacing scale contains 8px, 16px, and 24px. What should you do before handoff, and how would you write the spacing in the spec?
Show answer
Treat the 20px as an inconsistency. Ask whether it should be 16px or 24px and change it to the matching token, for example space-3 or space-4. If 20px is intended, add it to the scale as a named token first. Then write the spec with the token name, such as "padding: space-3", so the developer can map it to a CSS custom property.
Exercise
Your desktop layout uses 12 columns with a 24px gutter. Three cards sit in one row. How many columns does each card span, and what else should the spec state about the mobile layout?
Show answer
Each card spans 4 columns, because 12 divided by 3 is 4. The spec should also give the mobile column count, gutter, and outer margin, and say how the cards arrange themselves there, for example stacked in a single column.