CSS Typography, Web Fonts & Legibility

From high-performance system font stacks and @font-face WOFF2 optimization to unitless line-height and multi-line line-clamp truncation.

1. High-Performance System Font Stacks

A font stack is a prioritized, comma-separated list of fonts. The browser scans the list from left to right, rendering the first typeface installed on the client machine:

/* Modern Native System UI Font Stack */
font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif, "Apple Color Emoji", "Segoe UI Emoji";

Why use system font stacks? They load with 0ms latency (zero network requests), render with native operating system fidelity, and eliminate font layout shift entirely.

2. Web Font Loading Performance & font-display

When loading custom web fonts via @font-face, web performance hinges on the font-display descriptor:

StrategyBehavioral TimelineUser Impact & Core Web Vitals
font-display: swap
Recommended
Renders system fallback font immediately. Swaps in custom font as soon as the WOFF2 file arrives.Eliminates Flash of Invisible Text (FOIT); optimizes First Contentful Paint (FCP).
font-display: optionalGives the custom font ~100ms to load. If slow, uses fallback for the entire pageview.Zero Layout Shift (CLS): Ideal for low-bandwidth mobile connections.
font-display: blockHides text completely up to 3 seconds until custom font arrives.Causes jarring blank page syndrome on slow 4G networks.
@font-face {
  font-family: 'Inter';
  src: url('/fonts/inter.woff2') format('woff2');
  font-weight: 100 900; /* Variable font weight range! */
  font-display: swap;
  unicode-range: U+0000-00FF, U+0131, U+0152-0153; /* Subset Latin glyphs */
}

3. The Golden Rule of Unitless Line-Height

Always declare line-height as a pure number without units (e.g. 1.5, 1.6), never in pixels or percentages!

Why? With line-height: 1.5em on body (16px base), the line height is computed once as 24px and inherited as 24px by all descendants. When an <h1> has font-size: 36px, its lines crash together at 24px height. With unitless 1.5, the heading multiplies its own font-size dynamically: 36px * 1.5 = 54px!

CSS Example

/* Unitless line-height scaling properly across elements */
.prose-container {
  font-family: system-ui, sans-serif;
  line-height: 1.6; /* Unitless multiplier */
  max-width: 60ch;   /* Accessible reading measure */
  background: #fdfdfd;
  padding: 16px;
  border-left: 4px solid #3b82f6;
}

.prose-container h3 {
  font-size: 28px;
  margin-top: 0;
}

.prose-container p {
  font-size: 16px;
  color: #475569;
}

4. Text Truncation: Single-Line & Multi-Line Clamp

Preventing long text strings from destroying card layouts:

A. Single-Line Ellipsis Truncation:
.truncate-single {
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
B. Multi-Line Clamp (3-Line Truncation):

CSS Example

/* Multi-line truncation with line-clamp */
.clamp-three-lines {
  display: -webkit-box;
  -webkit-box-orient: vertical;
  -webkit-line-clamp: 2; /* Truncate after 2 lines! */
  overflow: hidden;
  font-size: 15px;
  line-height: 1.5;
  color: #334155;
  background: #f1f5f9;
  padding: 12px;
  border-radius: 6px;
  max-width: 320px;
}

5. Frequently Asked Questions (FAQ)

WOFF2 (Web Open Font Format 2.0) uses Brotli compression, resulting in files that are roughly 30% smaller than WOFF and 50% smaller than TTF/OTF. It is supported by 98%+ of global browsers. Providing legacy TTF, EOT, or SVG font formats in modern production codebases is completely unnecessary.

1ch equals the width of the "0" (zero) character in the currently active font. Extensive typographic research confirms that human reading comprehension is highest when lines contain between 45 and 75 characters. Setting max-width: 65ch on body copy guarantees optimal legibility across any screen size.

If a web font does not include a bold or italic variant, browsers will artificially synthesize "faux bold" or "faux italic" by smearing or slanting the normal font glyphs, producing ugly distorted typography. Setting font-synthesis: none prevents browsers from generating faux fonts.

Explore Related Tools

Hand-picked utilities and calculators related to this tool.

Related Tools