Sub topic 7
Typography: fonts, sizes, weights and line height
This chapter assumes you can open DevTools, read a Figma text style or PDF spec, and know CSS units such as px, rem and unitless line-height. Typography is where small differences are easy to miss by eye and easy to measure with the right tool.
What to compare
For each text style in the design (heading, body, caption, button label), check six properties on the built page:
- Font family, including the fallback that actually renders.
- Font size.
- Font weight.
- Line height.
- Letter spacing.
- Color, which is covered in the next chapter.
Check one example of each style, not every paragraph. If the style is defined once in CSS, one correct sample tells you about all of them.
Read the computed values
The Styles pane shows what the author wrote. The Computed pane shows what the browser used. Always compare the computed values, because 1.125rem and 18px are the same thing only after calculation.
This snippet prints those values 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
});Then compare the output with the spec in the table below.
| Property | Design says | Built page shows | Result |
|---|---|---|---|
| Font size | 32px | 32px | Match |
| Weight | 700 | 600 | Mismatch |
| Line height | 40px | 1.25 (computes to 40px) | Match |
Figma shows line height in pixels or as a percentage. A unitless CSS value of 1.25 on a 32px font computes to 40px, so these are equal.
Check the font that really rendered
font-family lists a stack of fonts. The first one may have failed to load, so the browser quietly uses the next one. In DevTools, select the element and open the Computed pane. Scroll to Rendered Fonts (in Chrome, it appears on the Elements panel's Computed tab). It names the font actually used.
Common errors
- Wrong weight. The font file for weight 600 was never loaded, so the browser uses 400 or 700 instead. Check that the
@font-facerule or font service request includes every weight in the design. - Faux bold or italic. The browser synthesizes a style it has no file for. Letters look smeared or unevenly thick compared with the design.
- Flash of fallback text. On a slow connection the page first shows a system font. Throttle the network in DevTools and reload to see it.
- Size drift. A heading is 31.2px because of nested
emvalues. The computed value reveals it. - Line height mismatch. Text looks tighter or looser than the design even when size matches. Compare the line height in pixels.
- Letter spacing in the wrong unit. Figma uses percentages, while CSS often uses
em. A 2% setting is0.02em.
Exercise
Exercise
The design specifies body text at 16px with a 24px line height. On the built page, the computed font size is 16px and the computed line height is 1.4. Does it match? What would you report if not?
Show answer
No. A line height of 1.4 on 16px text computes to 22.4px, not 24px. Report it as a mismatch: expected 24px (unitless 1.5), actual 22.4px (1.4). Include the element selector and the viewport width.