Sub topic 6
Layout, alignment and spacing
Layout is the first thing to check in a visual QA pass. If the boxes are in the wrong place, any typography or color check you do next will be measuring the wrong thing. This chapter assumes you can read the CSS box model (content, padding, border, margin), you know display: flex and display: grid at a basic level, and you can open DevTools and select an element. You also need the design open with its spacing values visible, for example a Figma frame in Inspect mode or a redline PDF.
What you are checking
Layout problems fall into four groups:
- Position: where an element's edges sit relative to the page and to its neighbors.
- Size: width and height of containers, buttons, cards and images.
- Spacing: padding inside elements and the gaps between them.
- Order and structure: which elements come first, which share a row, and which wrap.
Check these from the outside in. Start with the page container and its columns, then sections, then the components inside them, and last the small gaps inside components. An error at the container level, such as a content width that is 40px too wide, shifts everything inside it. If you start with the small gaps, you will log many false discrepancies that disappear once the container is fixed.
Step 1: Make every box visible
Before you measure anything, look at the structure. Paste this into DevTools (in the Elements panel, add it as a new style rule on html, or use a temporary stylesheet):
* {
outline: 1px solid rgba(255, 0, 0, 0.4);
}An outline is drawn outside the border and takes up no space, so the layout does not move. If you used border instead, every box would grow by 2px and the page would no longer match the design. With outlines on, you can see stray empty wrappers, elements that do not line up on a shared left edge, and gaps that are larger than they should be.
Step 2: Measure with DevTools
Select an element and open the box model diagram (in Chrome it is on the Computed tab, in Firefox on the Layout tab). It shows the content size, padding, border and margin. Compare these numbers with the design, using the right design value for each:
- A Figma "gap" between two frames usually corresponds to
marginor the CSSgapproperty. - A Figma "padding" corresponds to CSS
padding. - A redline that measures between two pieces of text may measure to the glyphs, while the browser measures to the text box. The two can differ by several pixels because of line height.
For repeated checks, measure distances with a script instead of dragging a ruler. This function returns the space between the bottom of one element and the top of the next, and the difference between their left edges:
function gap(selectorA, selectorB) {
const a = document.querySelector(selectorA).getBoundingClientRect();
const b = document.querySelector(selectorB).getBoundingClientRect();
return {
vertical: b.top - a.bottom,
horizontal: b.left - a.right,
leftEdgeDelta: b.left - a.left,
};
}
console.log(gap('h1', 'h1 + p'));A leftEdgeDelta of 0 means the two elements share a left edge. A value such as 0.5 is usually a fractional-pixel effect and is not worth reporting. A value of 8 or more is a real misalignment.
Step 3: Check the layout system, not only the numbers
Matching pixel values at one width is not enough. You also need to confirm that the page is built the way the design intends it to behave. Look at these in DevTools:
- Flex containers: enable the flex overlay badge in the Elements panel. Check
justify-content,align-items,gapandflex-wrap. - Grid containers: enable the grid overlay. Check that the column count, track sizes and gutters match the design's grid.
- Fixed versus fluid: a width written as
width: 1140pxmatches the design at one viewport and breaks at others. Amax-widthwith percentage padding usually reflects the design better.
A page can match the design at 1440px because someone typed the values in by hand, and it will still break when the window changes. The next chapters cover responsive checks in full. For now, resize slowly and watch whether the grid overlay's columns change at predictable points.
Common causes of layout mismatches
| Symptom | Likely cause | What to check |
|---|---|---|
| Element is 4px wider or taller than the design | `box-sizing: content-box` with padding added to the width | Computed `box-sizing`; the design size usually includes padding |
| Gap between two blocks is larger than the design | Both blocks have margin and one also has an outer wrapper | Margin on both elements; whether the design intends a gap or margins |
| Gap between two blocks is smaller than expected | Vertical margins collapsed into the larger one instead of adding | Adjacent block siblings with margin; use `gap` or padding to avoid |
| Text block looks taller than the redline | Line height adds space above and below the glyphs | Computed `line-height`; measure from the text box |
| Content shifts right by 15-17px on some pages | Vertical scrollbar takes up width on pages that scroll | Page height; whether the scrollbar is overlay or classic |
| Columns not equal width | Flex items sized by content instead of `flex: 1` or grid tracks | Computed width of each item |
| Last item in a row wraps early | Sum of widths plus gaps exceeds the container by a pixel or two | Container width versus the item widths and `gap` |
Alignment checks
Alignment is about shared edges and shared centers. Draw a vertical line mentally (or use the Figma guides in the design) and check these:
- Headings, body text and buttons in a column share the same left edge.
- Items in a row share a baseline or a vertical center, as the design shows.
- Icons sit centered against the first line of text, or against all of it, as designed.
- Cards in a row have equal heights where the design shows equal heights.
Baseline versus center is a frequent source of confusion. An icon next to a label looks wrong if it is centered on the box instead of the text, and the reverse is also true. Check align-items on the parent to see which was chosen, then compare with the design.
Setting a tolerance
Browsers round fractional values and lay out text in subpixel units, so a perfect pixel match is neither realistic nor useful. Agree on a tolerance with the designer before you start. A common working rule:
- 0-1px: accept, do not report.
- 2-3px: report if it repeats across a component or breaks an alignment line.
- 4px or more: report, and note the measured and expected values.
The exact numbers are a team decision. What matters is that everyone uses the same ones, so the report does not fill up with noise. Later chapters cover how to rank the differences you do find.
Writing down what you find
For each difference, record the element, the measured value, the expected value and the viewport width. A good note reads: "Card grid gap is 16px at 1280px wide, design shows 24px." A poor note reads: "Cards look too close together." The first one can be fixed without a conversation.
Exercise
A design shows 24px between a section heading and the paragraph below it. In DevTools, the gap() script returns vertical: 16, but the heading has margin-bottom: 24px. What are two likely explanations, and what do you check next?
Show answer
Two likely explanations: (1) The paragraph has a smaller margin-top and the margins collapsed, so the larger margin should still apply and the gap should be 24px. A result of 16 suggests the margin-bottom is on a different element than the one measured, such as a wrapper, or the heading is inside a flex or grid container where its margin is not what you think. (2) The heading's bottom edge in getBoundingClientRect() is the border box, so check whether a parent with overflow or a different box-sizing changes where the edge sits. Next, select the heading and the paragraph in the Elements panel, read the box model for each, and confirm which element carries the margin. Then check whether the parent is a flex or grid container, where margins do not collapse.