Skip to content
Velloreth
Design 10 min read

Typography for Developers: Practical Principles

A working guide to web typography for developers: type scales, line length, line height, font loading, variable fonts, and CSS that keeps text readable.

By

Typography is not a taste problem. It is a spacing problem, a loading problem, and a contrast problem, in that order. The typeface you choose matters less than whether the lines are the right length, the right height, and actually visible against their background.

Most developers meet typography through a framework’s default h1 sizes, discover that the result looks off, and start nudging values until it stops bothering them. This is a reasonable way to work, but it leaves you unable to say why it looks better. The principles below are the ones worth memorizing, because they transfer across every project and every font.

What typography actually controls

Every text style on a screen is a small set of interacting decisions:

PropertyWhat it decidesTypical starting point
Font sizeLegibility floor16–19px body, 1rem base
Line heightVertical rhythm, leading errors1.5 body, 1.1–1.25 headings
MeasureHow far the eye travels per line50–75 characters
Weight and colorHierarchy and contrast400/600/700, 4.5:1 minimum
Letter spacingDensity of small or uppercase text0 body, +0.02–0.06em uppercase
Type scaleRelationship between levelsRatio of 1.15–1.33

The important thing is that these are coupled. Increasing font size without touching measure gives you fewer characters per line and a different rhythm. Tightening line height is fine at 64px headings and disastrous at 16px body copy. Treat them as one system, not six independent sliders.

Measure: the constraint nobody sets

The measure is the number of characters on a line. Reading research has converged on a narrow range for body text: Baymard Institute’s usability testing puts the optimal line length at 50–75 characters, Emil Ruder argued for 50–60 in Typographie, and a literature review by Ling, Van Schaik and Bias recommends not exceeding about 70. Dyson and Haselgrove’s screen-reading study found 55 characters per line produced the highest comprehension at both normal and fast reading speeds.

There is also a formal accessibility number. WCAG 2.2 Success Criterion 1.4.8 (Visual Presentation, Level AAA) asks for lines of 80 characters or fewer, or 40 or fewer for Chinese, Japanese and Korean text.

On the web you do not count characters — you set a width and let the font do the counting:

.prose {
  max-width: 65ch;
  font-size: 1.125rem;
  line-height: 1.6;
}

ch is the width of the “0” glyph in the current font, which is a decent proxy for average character width. It has a useful property: change the font, and the container resizes to preserve the same character count. A fixed max-width: 720px does not.

Two caveats. First, ch is approximate — for a font with a narrow zero and wide lowercase, 65ch may come out closer to 50 actual characters. Check the real result. Second, max-width alone does nothing on a page where the parent is already narrow; measure the rendered line, not the CSS value.

Full-bleed paragraphs on a 27-inch monitor routinely hit 120–150 characters. Readers do not consciously register that this is the problem; they just stop reading as far down the page.

Line height: unitless, always

Line height should be a unitless multiplier, because a multiplier scales with font size:

body   { font-size: 1.125rem; line-height: 1.6; }
h2     { font-size: 2rem;     line-height: 1.2; }

Write line-height: 1.6 in a stylesheet that uses rem for font sizes and every level inherits a proportional rhythm. Write line-height: 28px and you get a fixed gap that feels correct at 16px and cramped at 22px the moment you change one size.

Sensible defaults, adjusted to your font’s x-height and ascender:

ContextLine height
Long-form body1.5–1.7
UI labels, buttons1.2–1.4
Headings (24px+)1.1–1.3
Code blocks1.5–1.6
All-caps overlines1.4–1.5

Serif faces with short x-heights tolerate tighter leading; geometric sans faces with tall x-heights usually need more. Set a value, read a full paragraph, and adjust.

The classic related technique is a modular vertical rhythm — multiples of a base unit, so every margin is 8px, 16px, 24px, 32px. It works well in design systems and becomes a straitjacket the moment content needs an exception. Use the idea, not the religion.

A type scale that survives content

A type scale is a ratio applied to a base size. With a base of 17px and a ratio of 1.2 (a “minor third”):

StepSizeUse
017pxBody
120.4pxLead paragraph, large body
224.5pxSmall heading, card title
329.4pxSection heading
435.3pxPage heading
542.3pxHero

Two adjustments make scales behave in reality. First, use clamp() so headings compress gracefully instead of stepping down at a breakpoint:

h1 {
  font-size: clamp(2.25rem, 1.6rem + 2.8vw, 4rem);
}

Second, let small text stay small and large text stay large. Compressing an entire scale into a narrow band at mobile widths produces headings that are indistinguishable from body copy, which destroys hierarchy — the one thing a scale exists to provide.

Do not skip steps for emphasis. If a heading needs to be bigger than its level, either it belongs at the next level, or the level’s meaning is wrong.

Weight, color, and where text actually fails

Hierarchy comes from size, weight, color, and spacing — in roughly that order of reliability. Color is the weakest signal because it disappears for color-blind readers, in forced-colors mode, and in print.

The hard floor is contrast. WCAG 2.2 requires 4.5:1 for normal text (SC 1.4.3, AA), 3:1 for large text (18px regular or 14px bold, about 24px and 18.7px in CSS), and 3:1 for the visual boundaries of UI components and meaningful graphics (SC 1.4.11). Passing the ratio is necessary and not sufficient: #767676 on white clears 4.5:1 and still looks like an apology.

Practical rules that hold up:

  • Set muted text to a color that hits at least 4.5:1 against its real background, not an idealized one. Over images, verify against the brightest region.
  • Do not use opacity to create secondary text. Opacity changes the effective contrast against whatever is behind it, and you lose the ability to test one value. Use an explicit color token.
  • Bold is not a substitute for size. Semi-bold text below 18px still struggles.
  • Test at the smallest size you ship, not at 16px in a design file when the component renders at 13px.

Font loading is a layout problem

Webfonts break layouts in two ways: they arrive late and shift the text, or they never arrive and leave a fallback that looks wrong. Both are fixable.

Self-host. Serving fonts from your own origin avoids a third-party DNS lookup and lets you cache them alongside your CSS. Subset to the scripts you actually use — a Latin-only woff2 for English content is a fraction of the size of a full family.

Reserve metrics. When a webfont loads after the fallback, the line breaks change and the page jumps. The modern fix is metric overrides on the fallback:

@font-face {
  font-family: "Inter Fallback";
  src: local("Arial");
  size-adjust: 107%;
  ascent-override: 90%;
  descent-override: 22%;
  line-gap-override: 0%;
}

With a matched fallback, the swap is invisible instead of a shift.

Pick a display strategy deliberately. font-display: swap renders fallback text immediately and swaps — good for perceived performance, bad if the metrics differ. font-display: optional gives the font a short block period and then commits to the fallback for that page load: no shift, no flash, but the font may not appear on a first visit. For a branded site, swap with metric overrides is usually right. For an app UI where layout stability matters more, optional or a system stack is better.

Preload only the face you preload correctly. <link rel="preload" as="font" type="font/woff2" crossorigin> for the primary weight. Preloading a font you never use, or forgetting crossorigin (fonts are always fetched in CORS mode, even same-origin), wastes the request budget.

Variable fonts and optical sizing

A variable font gives you a weight axis (and often width, slant, and optical size) in a single file. The win is not always file size — it is that you can hit any weight instead of only 400 and 700, which means you can choose 500 for UI labels where 600 would look shouty.

The optical size axis (opsz) is the one most projects ignore. Typefaces designed for print have thin hairlines at large sizes and sturdier strokes at small sizes. When you render a display cut at 14px, those hairlines disappear. Optical sizing restores them:

body {
  font-family: "Source Serif 4", serif;
  font-optical-sizing: auto;
}

Browsers map opsz to the computed font size automatically when the font declares the axis. Set font-optical-sizing: none only if you specifically want one optical size everywhere.

Subsetting matters more with variable fonts: an unconstrained variable family can be larger than the static weights it replaces. Check the actual bytes.

The small details that fix most complaints

Text that looks “bad” is usually one of these, not the typeface:

  • Widows and orphans. text-wrap: balance on headings and short paragraphs stops a one-word last line. text-wrap: pretty (supported in current Chromium and Firefox) reduces bad breaks in body copy. Both are progressive enhancements — no fallback work required.
  • Hyphenation. For justified or narrow columns, hyphens: auto with a lang attribute on the element dramatically improves ragged edges. Without lang, browsers will not hyphenate.
  • Tabular numerals. Any column of numbers — prices, timestamps, stats, tables — needs font-variant-numeric: tabular-nums or the digits will not align, because proportional figures have different widths.
  • Uppercase labels. Small all-caps text needs tracking to stay legible: letter-spacing: 0.05em and up. Never letterspace lowercase body text; it breaks word shape.
  • Text rendering. Avoid forcing -webkit-font-smoothing: antialiased. On macOS it makes text lighter and reduces effective contrast against the background, which can quietly push you below 4.5:1.
  • Code blocks. Use a monospace with a clear distinction between 1, l and I, and 0 and O. Ligatures are a preference; disabling them in code with font-variant-ligatures: none keeps != from rendering as ≠.

A minimal starting stylesheet

Enough theory — a base you can paste into a project and adjust:

:root {
  --text: 1.0625rem;          /* 17px */
  --leading: 1.6;
  --measure: 65ch;
  --step-0: 1rem;
  --step-1: 1.2rem;
  --step-2: 1.44rem;
  --step-3: 1.728rem;
  --step-4: 2.074rem;
  color-scheme: light dark;
}

html {
  font-size: 100%;
  -webkit-text-size-adjust: 100%;
}

body {
  font-family: system-ui, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  font-size: var(--text);
  line-height: var(--leading);
  text-rendering: optimizeLegibility;
}

p, ul, ol { max-width: var(--measure); }

h1, h2, h3, h4 {
  line-height: 1.2;
  text-wrap: balance;
  font-weight: 650;
}

h1 { font-size: var(--step-4); }
h2 { font-size: var(--step-3); }
h3 { font-size: var(--step-2); }

code, pre, kbd {
  font-family: ui-monospace, "SF Mono", Menlo, Consolas, monospace;
  font-variant-ligatures: none;
}

table { font-variant-numeric: tabular-nums; }

a { text-underline-offset: 0.15em; }

@media (prefers-reduced-motion: no-preference) {
  html { scroll-behavior: smooth; }
}

The scale is a minor third (1.2) starting from the base. The measure is 65ch. Line heights are unitless. Nothing here depends on a downloaded font, so it renders correctly on first paint.

Where to spend your remaining effort

Run down this order: measure, line height, contrast, size, then typeface. If your text reads poorly after the first four are right, the problem is genuinely the typeface — and then it is worth investing in a proper choice with a full character set, good numerals, and a license you understand.

Verify by reading, not by looking. Open a real article on your site, set the window to the width a reader would actually use, and read three paragraphs without squinting or scrolling horizontally. If you can do that, your typography is doing its job, and nobody will ever notice — which is the entire point.

Frequently asked questions

What is the single most impactful typography change for a content site?
Constrain the measure. Set a max width of roughly 60 to 70 characters on body copy and pair it with a unitless line height near 1.5. Those two changes fix more reading fatigue than swapping typefaces ever will.
How do I pick a type scale?
Pick a base size, choose a ratio between 1.15 and 1.33, and derive heading sizes from it — but clamp them at breakpoints so mobile headings do not shrink to illegibility. A scale is a starting constraint, not a rule you defend against real content.
Should I use a system font stack or a webfont?
Use a system stack for UI and dense product screens: it is free, instant, and already installed. Reach for a webfont when the typeface carries brand identity, and then self-host it with subsets, preload, and font-display set to swap or optional.
What font size should body text be?
Start at 16px and go up, not down — 17 to 19px reads better for long-form on desktop and mobile alike. What matters more is that the size, line height, and measure work together; a 14px paragraph with a 60-character measure will fail regardless of the face.