Book 3 — HTML, CSS Basics

Python for All

Chapter Six — Typography & Layout

Thanasis Troboukis  ·  All Books

Book Three · Chapter Six

Typography & Layout

The difference between a page that is painful to read and one that readers stay with for ten minutes comes down to typography and spacing. This chapter gives you the tools.

Font Properties

Typography is not decoration — it is the primary vehicle through which your readers experience your writing. The properties that control it are few, but their effect is enormous.

font-family sets the typeface. You list multiple fonts separated by commas — the browser will use the first one it can find. The last item should always be a generic family like serif, sans-serif, or monospace as a fallback.

font-size sets the size. Use px for fixed sizes, or em/rem for sizes relative to the base font. For body text, 17–19px is a comfortable reading size.

font-weight sets the boldness: 400 is regular, 700 is bold. Some fonts have intermediate weights like 600.

font-style sets italic: italic or normal.

CSS · Try it — font properties

HTML

CSS

Live Preview

Line Height and Letter Spacing

line-height is the vertical space between lines of text. For body text, a line height of 1.6 to 1.8 is standard — it creates breathing room between lines and dramatically improves readability. Values without a unit (like 1.75) are relative to the font size.

letter-spacing is the horizontal space between individual characters. Body text rarely needs it. But uppercase labels and kickers often benefit from a small positive value (e.g. 0.12em) to improve legibility at small sizes.

text-transform changes capitalisation without touching the HTML: uppercase, lowercase, or capitalize (first letter of each word).

CSS · Try it — line height and spacing

HTML

CSS

Live Preview

The Box Model — Margin and Padding

Every HTML element is a rectangular box. CSS controls the space around and inside it with two properties:

Both can be set uniformly (margin: 20px), or individually per side: margin-top, margin-right, margin-bottom, margin-left. A shorthand with four values sets them in that order: margin: top right bottom left.

CSS · Try it — box model

HTML

CSS

Live Preview

max-width and Centering — The Reading Column

Long lines of text are hard to read. Eye-tracking studies suggest that a comfortable line length is 60–75 characters. This translates to roughly 600–700px for a 17–18px font.

Use max-width to cap the width of your article body. Then center it horizontally with margin: 0 auto — this automatically distributes the remaining space equally on both sides.

CSS · Try it — centered reading column

HTML

CSS

Live Preview

What you have learned in this chapter: font properties, line height, letter spacing, the box model (margin and padding), and how to create a centered reading column with max-width. Next chapter: embedding maps, videos, and other media directly in your article.

Chapter Navigation

Move between chapters.