liveBook · Manning

Chapter 12: Typography and spacing

What you will learn in chapter 12 of CSS in Depth, Second Edition

The chapter introduces typography and element spacing as related parts of refining a page’s design.

After this chapter you will be able to

What it builds on

Section by section

Introduction

The chapter introduces typography and element spacing as related parts of refining a page’s design.

Key terms: spacing, fonts, layout

12.1 Spacing

This section frames matching a designer’s element spacing as an iterative task that usually starts with margins.

Key terms: spacing, margins

12.1.1 Using ems vs. px

This subsection shows how to choose relative or pixel units for spacing and how to place that space around navbar items and larger page elements.

Key terms: ems, rems, px, base font size, padding, margins, flexbox gap, nav-container__inner

12.1.2 Factoring in line height

This section shows how to account for line height when matching the visible spacing around text to a design mockup.

Key terms: line height, content box, margin, perceived space, ems, padding, margin collapsing, hero__inner, slogan, top padding

12.1.3 Spacing inline elements

This section shows how to space a wrapping list of inline tags without overlap and how that choice differs from flex or inline-block layouts.

Key terms: inline element, padding, line height, tag-list module, inline elements, flex item, inline-block, natural whitespace, line wrap

12.2 Web fonts

This section explains how web fonts expand font choices, affect a page’s tone, and can be selected and paired for headings and body text.

Key terms: web-safe fonts, system fonts, web fonts, @font-face, fallback, typeface, tone, Google Fonts, Adobe Fonts, hosting

12.3 Google fonts

This section shows how to select Google Fonts, limit the variants downloaded, embed the supplied stylesheet, and apply the fonts with CSS.

Key terms: Google Fonts, font families, Get Font, Get Embed Code, typeface, font, variants, weights, Roboto Light (300), Sansita Extra-bold (800)

12.4 How @font-face works

This section explains how @font-face rules connect a font name and rendering requirements to a downloadable file, and why Google splits character sets across font files.

Key terms: @font-face, font-family, src, font style, weight, unicode-range, Latin characters, extended character sets

12.4.1 Font formats and fallbacks

This section explains why a web font declaration may offer multiple file formats and how an installed font can avoid a download.

Key terms: WOFF2, Web Open Font Format, font formats, local(), network request

12.4.2 Multiple variants of the same typeface

The section explains how to define multiple variants of a web typeface and why pages should use only variants they have supplied.

Key terms: @font-face, typeface, font-weight, font-style, faux bold, faux italic

12.5 Performance considerations

This section explains the performance tradeoffs users experience while web fonts load and shows how to test font-loading behavior on a slow connection.

Key terms: web fonts, system font, fallback, FOUT, FOIT, DevTools, Network tab, Regular 3G, Disable Cache

12.5.1 The font-display property

This section explains how font-display controls what readers see while web fonts load, then introduces font-relative units and their layout risks.

Key terms: font-display, @font-face, FOIT, FOUT, block, swap, fallback, optional, &display=swap, lh

12.5.2 Variable fonts

This section explains how variable fonts provide multiple font styles in one file and how CSS controls their supported variation axes.

Key terms: variable fonts, font weights, typeface, variation axis, weight axis, @font-face, font-weight, font-variation-setting, registered axes, 'wght'

12.6 Adjusting space for readability

The section explains how balanced line and letter spacing make web-font text more comfortable to read.

Key terms: line-height, letter-spacing

12.6.1 Body copy spacing

This section explains how to tune line height and letter spacing for readable body copy and how to translate designers’ leading and tracking values into CSS.

Key terms: line-height, normal, body copy, letter-spacing, em, leading, tracking

12.6.2 Headings, small elements, and spacing

This section shows how to check heading spacing and adjust typography for short text and navigation without disrupting layout or tying design choices to HTML content.

Key terms: headings, line height, line wrap, body copy, letter-spacing, negative letter spacing, slogan, nav-container, align-items: end, ems

12.7 Summary

Concepts explained in this chapter

← Chapter 11: Color and contrast Chapter 13: Gradients, shadows, and blend modes →

These guides are generated from the text of Manning books by Manning's knowledge graph and link to the sections they draw on. The full books are available on liveBook and at manning.com.