Sub topic 4
Measuring the Built Page with DevTools
This chapter assumes you know the CSS box model, selectors and units, and that you can open browser DevTools. It also assumes you can read a design file and get values such as font size, spacing and color from it. Here you will learn to read exact values from the built page so you can compare them with the design instead of judging by eye.
What DevTools can tell you
DevTools is the set of inspection panels built into the browser. For a visual QA pass you use three of them:
- Elements panel. It shows the DOM (the page's element tree) and the CSS rules that apply to the selected element.
- Computed pane. It shows the final value of every CSS property after the cascade, inheritance and unit conversion. It also shows the box model diagram.
- Console. It lets you run JavaScript against the live page, so you can read values in bulk.
The key idea is that you compare computed values with the design. The authored CSS might say 1.25rem, but the design says 20px. The Computed pane shows 20px and settles the question. Authored CSS can also be overridden by a later rule, so the declared value may not be the one in effect.
Inspecting one element
Right-click the element and choose Inspect. Then work through these checks.
- Select the right element. Click the element in the Elements panel, not just the visible text. A button's padding belongs to the
button, not to the label inside it. - Read the box model. The Computed pane shows concentric boxes for margin, border, padding and content. Hover over the diagram to highlight each area on the page.
- Check the rules. The Styles pane lists matching rules from most to least specific. Struck-through declarations were overridden. A yellow warning icon means the declaration has no effect, for example
widthon an inline element. - Check the computed value. Search for the property in the Computed pane. Expand it to see which rule won.
Reading sizes correctly
The box model has a trap. The width you read depends on box-sizing.
| `box-sizing` | What `width` includes | Typical result |
|---|---|---|
| `content-box` (browser default) | Content only | Padding and border make the box wider than `width` |
| `border-box` | Content, padding and border | The box is exactly `width` wide |
Designers measure the visible box, which is the border-box. If the design says a card is 320px wide, compare it with the border-box size shown at the outer edge of the box model diagram, or with getBoundingClientRect(). Do not compare it with the width declaration alone.
Measuring distances
Spacing is the most common source of small defects. Use these tools in order of speed.
- Hover highlight. Hovering an element in the Elements panel shows its size and its margin (orange) and padding (green) overlays.
- Alt/Option hover. In Chrome and Edge, select an element, then hold Alt (Option on macOS) while hovering another. The browser draws the distance between the two. Firefox offers a measuring tool in the toolbar's "Measure a portion of the page" button.
- Console. For exact numbers, use
getBoundingClientRect(). It returns the position and size of the border-box relative to the viewport.
const a = document.querySelector('.card-title').getBoundingClientRect();
const b = document.querySelector('.card-body').getBoundingClientRect();
console.log('gap between title and body:', b.top - a.bottom);Margin collapsing can make this number differ from what you expect. Adjacent vertical margins of block elements combine into the larger of the two rather than adding. If the design says 16px above and 24px below, the built page may correctly show 24px between the two elements. Check what the design intends before you report a mismatch.
Reading typography and color
Typography differences are easy to miss because many fonts look alike. Select the element, then read the values in the Computed pane or in the console:
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
});Two points need care:
fontFamilyshows the declared stack, not the font that rendered. If the web font failed to load, the browser falls back to the next family. In Chrome, open the Computed pane and scroll to "Rendered Fonts" at the bottom. In Firefox, use the Fonts tab. This shows the font actually used.lineHeightmay returnnormal. That means the browser chose a value from the font. A design spec will state a number, so a result ofnormalis a mismatch worth noting.
Colors come back as rgb() or rgba(), while design files usually give hex. Convert before comparing, or use the color picker in the Styles pane, which can switch formats. Be aware of transparency. A text color of rgba(0, 0, 0, 0.6) over a white background looks like a gray, and a design tool may list that gray as a solid hex value. Compare what the eye sees only after you have confirmed the alpha value.
Checking contrast
Contrast is the difference in brightness between text and its background. WCAG, the Web Content Accessibility Guidelines, sets minimum ratios: 4.5:1 for normal text and 3:1 for large text (roughly 24px regular or 18.66px bold and above).
Chrome's color picker shows the ratio and marks whether it passes. To check several pairs quickly, you can compute the ratio yourself:
function luminance([r, g, b]) {
const lin = (c) => {
c /= 255;
return c <= 0.04045 ? c / 12.92 : Math.pow((c + 0.055) / 1.055, 2.4);
};
return 0.2126 * lin(r) + 0.7152 * lin(g) + 0.0722 * lin(b);
}
function contrastRatio(fg, bg) {
const [hi, lo] = [luminance(fg), luminance(bg)].sort((a, b) => b - a);
return (hi + 0.05) / (lo + 0.05);
}
console.log(contrastRatio([119, 119, 119], [255, 255, 255]).toFixed(2));The example prints about 4.48. Mid-gray #777 on white looks acceptable, yet it falls just under 4.5:1. This kind of failure is the reason to measure rather than trust your eyes. If the design itself specifies the failing pair, report it as a design issue, not a build defect.
Making edges visible
When a layout looks slightly off, outline every element. Outlines do not change the layout, unlike borders, which add to the box size.
/* Paste into DevTools or a temporary stylesheet to see every element's box */
* {
outline: 1px solid rgba(255, 0, 0, 0.4);
}Misaligned left edges, unexpected gaps and elements that overflow their parents become obvious. Remove the rule when you are done.
Common errors when measuring
- Measuring at the wrong zoom or pixel density. Browser zoom changes CSS pixel sizes in the layout. Reset to 100% first. The previous chapter on setting up a fair comparison covers this.
- Reading the wrong pseudo-state. A button's hover color is not in the default computed values. Use the
:hovtoggle in the Styles pane to force:hover,:focusor:activebefore reading. - Trusting fractional values blindly. A computed width of
341.328pxis normal with percentage orfrunits. Compare with a tolerance of about 1px unless the design is explicit. - Confusing
remandpx. If the root font size is not 16px,1.5remis not 24px. Read the computed pixel value. - Inspecting a different build. Hard-reload with the cache disabled (Network panel, "Disable cache") so you are not measuring stale CSS.
Exercises
Exercise
A design says a card is 320px wide with 24px padding. In DevTools the card's width declaration is 320px, but the box model diagram shows an outer size of 368px. What is the likely cause, and what do you check?
Show answer
The card uses box-sizing: content-box, so the 24px padding on each side adds 48px to the 320px content width (320 + 48 = 368). Check the computed box-sizing. The design measures the visible box, so the build should either use border-box or set width: 272px for the content. Report the visible width (368px against 320px) as the discrepancy.
Exercise
The console shows fontFamily as "Inter", sans-serif for a heading, yet the text looks like Arial. How do you confirm which font rendered, and what is the probable cause?
Show answer
Open the Computed pane and check "Rendered Fonts" in Chrome, or the Fonts tab in Firefox. If it lists Arial or a similar system font, the Inter web font did not load. Common causes are a wrong font file path, a blocked request or a missing weight. Check the Network panel for a failed font request.