Sub topic 4
Measuring the built page with DevTools
This chapter assumes you can open browser DevTools, know the CSS box model and units, and have a design file with specs open beside the page. You will learn to read real measurements from the built page so you can compare them with the design.
Why measure instead of eyeballing
A page can look right and still be 3px off, or use #777 where the design says #6B6B6B. DevTools reports the values the browser actually applied. Compare those numbers with the spec, not with your impression.
Inspect the box model
Right-click an element and choose Inspect. In the Elements panel, open the Computed tab. The box-model diagram shows the content size, padding, border and margin in pixels.
Hover over the element in the DOM tree. The page highlights its margin, padding and content areas in different colors, so you can see where space comes from.
Check these first:
- Width and height of the element against the redline.
- Padding inside the element and margin outside it.
- The gap between siblings. This may come from
gapon a flex or grid parent, not from margins.
Find where a value comes from
The Styles tab lists every rule that applies, with the winning declaration on top. Struck-through declarations lost to a more specific rule. If a value looks wrong, this tab shows which rule to blame, which makes your report more useful.
Computed values are always in pixels (for example rem becomes 16px). Convert the design's units before you compare.
Read typography and color in the console
Clicking through several elements is slow. The console can print the values you need in one step:
const el = document.querySelector('h1');
const s = getComputedStyle(el);
console.log({
fontFamily: s.fontFamily,
fontSize: s.fontSize,
fontWeight: s.fontWeight,
lineHeight: s.lineHeight,
letterSpacing: s.letterSpacing,
color: s.color
});Change the selector to check other elements. The color comes back as rgb(...), so convert the design's hex value before you compare.
Make misalignment visible
To see every element's box, paste this into the console's style editor or a temporary stylesheet:
* {
outline: 1px solid rgba(255, 0, 0, 0.4);
}An outline does not affect layout, so nothing shifts while you look. Edges that should line up but do not now stand out.
Match values to checks
| What you check | Where in DevTools |
|---|---|
| Width, height, padding, margin | Computed tab, box-model diagram |
| Which rule sets a value | Styles tab |
| Font, size, weight, line height | Computed tab or console |
| Font actually rendered | Computed tab, Rendered Fonts |
| Color value | Styles tab color swatch, or console |
Common mistakes
- Editing in DevTools and forgetting. Changes are lost on reload. Note the correct value in your report.
- Measuring at the wrong zoom. Browser zoom changes the pixel values you read. Reset it to 100% first.
- Comparing against the wrong width. Inspect the page at the same viewport width as the design frame.
Exercise
The design specifies body text at 16px with a 24px line height. In the console, getComputedStyle reports lineHeight as "normal". What does this tell you, and what should you report?
Show answer
"normal" means no explicit line height is set, so the browser uses the font's default, which is usually about 1.2 times the font size and does not match 24px. Report it as a discrepancy: expected 24px (1.5), actual "normal". Then find the rule in the Styles tab, or note that none sets it.