TetSharing
CSS tutorial · 12 chapters
  1. Get started
  2. Selectors
  3. Cascade and specificity
  4. Colors
  5. Units and sizes
  6. Box model
  7. Text and fonts
  8. Flexbox
  9. Grid layout
  10. Media queries
  11. Custom properties
  12. Transitions

Final CSS quiz
Cheat sheet: css selectors

Chapter 7 of 12 · By Ethan Cole · Updated November 21, 2026

CSS Typography: Fonts, Sizes, Line Height and Weight

Most of a web page is text, so typography matters more than any other styling. A few properties do most of the work.

font-family and font stacks

font-family takes a comma-separated list. The browser uses the first font that is installed and falls back along the list:

body { font-family: "Inter", system-ui, -apple-system, "Segoe UI", Roboto, sans-serif; }

Names with spaces need quotes. Always finish with a generic family: serif, sans-serif, monospace or system-ui. system-ui asks for the operating system's interface font, which looks native and costs no download, a good default for fast sites.

Size and weight

  • font-size sets the height of the text. Use rem so readers' font preferences carry through.
  • font-weight takes normal (400), bold (700) or a number from 100 to 900. A number only has a visible effect if the font has that weight.
  • font-style: italic slants the text.

Line height and measure

line-height controls the vertical space each line occupies. Write it without a unit, like line-height: 1.6: a unitless value is multiplied by each element's own font size, so headings and small print both get proportional spacing. With a unit such as px, the computed value is fixed and inherited as-is, which cramps larger text. Body text reads comfortably around 1.5 to 1.7.

Line length matters too. Lines of roughly 60 to 75 characters are easiest to follow, and max-width: 65ch keeps a column near that, since ch is the width of the "0" character.

Alignment and spacing

text-align takes left, right, center or justify. letter-spacing adds space between characters, useful for small uppercase labels. text-transform: uppercase changes the displayed case without changing the HTML, so screen readers and copy-paste still get the original text.

The example sets these properties on a heading and a paragraph and prints a few computed values. Note how the unitless line height becomes a pixel value based on each element's own size.

HTML · editable

Expected page text

CHAPTER 7
Readable text
Comfortable line height and a sensible line length make long reading easy.
h1 line-height: 48px
p line-height: 28.8px
h1 font-weight: 700
label transform: uppercase

Web fonts

To use a font the reader may not have, declare it with @font-face and a woff2 file served from your own site, and set font-display: swap so text appears immediately in a fallback font while the custom one loads. Each weight is a separate file, so load only the weights you use.

Summary

  • End every font-family list with a generic family; system-ui is fast and native.
  • Use rem for font-size and a unitless line-height.
  • Keep lines readable with max-width in ch.

Quiz: Text and fonts

1. Why should a font-family list end with a generic family like sans-serif?

The browser walks the list and needs a guaranteed last option.

2. An element has font-size 20px and line-height 1.5. What is its computed line height?

A unitless line-height is multiplied by the element's own font size: 20 x 1.5 = 30px.

3. What does text-transform: uppercase change?

The source text stays the same; only the rendering is uppercase.

Official docs

Written under the pen name Ethan Cole with AI-assisted drafting. Every code example on this page is executed by our test suite before publishing. Found a mistake? Tell us.