# Font Sizing & Spacing

> How font-size, line-height, letter-spacing, and word-spacing combine to make text readable, and why a unitless line-height is the one form you should reach for.

Subject: CSS | Lesson 11 of 44 | 6 min read
Interactive lesson: https://codewithanimation.in/css/font-sizing-and-spacing
Previous: [Fonts & Web Font Loading](https://codewithanimation.in/css/fonts-and-web-fonts.md) | Next: [Text Styling & Wrapping](https://codewithanimation.in/css/text-styling-and-wrapping.md)

## Four properties that decide how text fills its space

`font-size` sets the size of the glyphs. The unit you pick decides what it is relative to: `px` is fixed, `rem` is relative to the root element, and `em` or `%` are relative to the parent element's font-size (and compound when nested).

`line-height` sets the height of each line box. The unitless form like `1.5` is a multiplier: each line is 1.5 times the element's own font-size. The form `1.5em` or `150%` is computed once at the element where it is set and then inherited as a fixed pixel value.

`letter-spacing` adds (or removes, if negative) space between every character. `word-spacing` does the same but only between words. Both inherit and both take a length relative to the element's own font-size when you use `em`.

## Readable text is mostly line-height and spacing

Long body copy at `line-height: 1` is hard to read because the eye loses its place between lines. Bumping to `1.5` gives the eye a clear gap to track, which is why WCAG Success Criterion 1.4.12 asks for at least 1.5 on body text. The unitless form keeps that gap proportional no matter what font-size a child uses.

`letter-spacing` and `word-spacing` are how you tune a headline from default system spacing into something that looks set by a designer. Tightening a large headline by `letter-spacing: -0.02em` removes the optical gaps caps leave, and loosening small uppercase labels by `0.1em` makes them legible.

Knowing that `em` and `%` compound through nesting is what stops a component from blowing up when it gets dropped inside a larger text context. `rem` for sizes and unitless multipliers for line-height are the predictable defaults for exactly this reason.

## The values and forms that matter day to day

**font-size units:** `px` (fixed, 16px is the browser default), `rem` (relative to the root, scales with user font-size preference), `em` and `%` (relative to the parent, compounds when nested), and keywords like `small` / `medium` / `large`. For most component sizing, `rem` is the safe pick because it never compounds.

**line-height:** prefer the UNITLESS form. `line-height: 1.5` is inherited as a multiplier, so a child with `font-size: 2rem` gets a 3rem line box automatically. `line-height: 1.5em` computes to a fixed pixel value at the parent and is inherited as that fixed number, which breaks proportional spacing in any child whose font-size differs.

**letter-spacing:** takes a length, usually in `em` so it scales with the font. `letter-spacing: -0.02em` tightens a headline, `0.1em` loosens a small uppercase label. It applies to every character including the last one in a word, which is why a small negative value on tightly-set caps often looks better than none.

**word-spacing:** adds space between words, not characters. Useful for justified text or small uppercase labels. Inherited, and `em` is relative to the element's own font-size.

**The `font` shorthand:** `font: italic 700 1.25rem/1.5 \"Inter\", sans-serif;` sets style, weight, size, line-height, and family in one declaration. Size and family are required and must be in that order, with line-height after a slash right after the size. Forgetting any sub-property in the shorthand RESETS it to the initial value, so `font: 1rem \"Inter\";` silently sets `line-height: normal` even if you set `1.5` elsewhere.

## Common mistake: line-height: 1.5em is not line-height: 1.5

The single most common spacing bug: a developer writes `line-height: 1.5em` (or `150%`, or `24px`) on a wrapper, expecting proportional spacing everywhere inside. What actually happens is the browser computes the line height ONCE, in pixels, at the wrapper, and inherits that fixed number. A child with a bigger `font-size` then gets a line box sized for the parent, so its lines overlap or feel cramped. The fix is to drop the unit: `line-height: 1.5`. The unitless value is inherited as a multiplier, so every descendant multiplies by its OWN font-size and the spacing stays proportional at every size.

## Tip: Use rem for sizes, unitless for line-height

Pair `font-size` in `rem` with a unitless `line-height` and you get text that scales with the user's root font-size preference AND keeps proportional spacing in every nested component. This is the single combination that survives being dropped into any layout without surprise. Reach for `em` and `%` only when you deliberately want a size to be relative to its parent, and reach for a unit on `line-height` only when you want a fixed pixel leading.

## Try it: Try it

See `line-height` at 1, 1.5, and 2 on the same paragraph with a baseline grid revealing the rhythm, then compare `letter-spacing` tight, normal, and loose on a headline.

The animation is on the lesson page and is not part of this text version: https://codewithanimation.in/css/font-sizing-and-spacing

## Check yourself

### Question 1

You set `line-height: 1.5em` on a card wrapper. A child inside it has `font-size: 2rem` (twice the wrapper's size). What line-height does the child get?

- A. A fixed value equal to 1.5 times the WRAPPER's font-size, inherited as pixels
- B. 3rem, computed as 1.5 times the child's own 2rem font-size
- C. normal, because the child overrides the inherited value
- D. 1.5em relative to the child's font-size

Correct answer: A

Any unit on `line-height` (`em`, `px`, `%`) makes the browser compute a fixed pixel value at the element where the property is set, and that fixed number is what gets inherited. The unitless form `1.5` is inherited as a multiplier, so each descendant recomputes against its own font-size. For proportional spacing at every size, use the unitless form.

- Why not B: That is what the UNITLESS `1.5` would do. The `em` form is computed once at the wrapper and inherited as a fixed pixel value, so the child does not re-multiply by its own size.
- Why not C: The child does not override anything unless it sets its own `line-height`. Inheritance passes the wrapper's computed value down.
- Why not D: `em` inside `line-height` is relative to the element WHERE THE LINE-HEIGHT IS DECLARED, not the inheriting child. So it locks to the wrapper's size, not the child's.

### Question 2

You write `font: 1.25rem "Inter";` on a heading. Earlier in your stylesheet you set `line-height: 1.4` globally. What is the heading's line-height?

- A. normal, because the `font` shorthand resets every omitted sub-property to its initial value
- B. 1.4, inherited from the global rule
- C. 1.25rem, because line-height defaults to the font-size
- D. 1.75rem, computed as 1.4 times 1.25rem

Correct answer: A

The `font` shorthand is unforgiving: every sub-property you omit is reset to its initial value. Forgetting `/line-height` resets it to `normal`, forgetting `weight` resets it to `normal` (400), and so on. Either include the value in the shorthand or set the sub-property separately AFTER the shorthand.

- Why not B: The `font` shorthand is a reset. Any sub-property you leave out, including `line-height`, is reset to `normal`. The global `1.4` is overridden by the shorthand declaration.
- Why not C: line-height does not default to font-size. Its initial value is `normal` (roughly 1.2, browser-dependent), and the shorthand forces it back to that.
- Why not D: That would require the unitless `1.4` to survive, but the `font` shorthand resets `line-height` to `normal`. To keep the 1.4 you must write it in the shorthand: `font: 1.25rem/1.4 "Inter";`.

### Question 3

Which `letter-spacing` value would most likely make a large uppercase headline look tighter and more optically balanced?

- A. letter-spacing: -0.02em
- B. letter-spacing: 0.1em
- C. letter-spacing: normal
- D. letter-spacing: 2px

Correct answer: A

Large glyphs, especially capitals, leave optical gaps that look loose at default tracking. A small negative `letter-spacing` like `-0.02em` tightens those gaps. The value is in `em` so it scales with the headline's font-size, unlike `px`.

- Why not B: A positive value LOOSENS spacing, which is the opposite of tightening. `0.1em` is what you would use on small uppercase labels to make them readable, not on a large headline.
- Why not C: `normal` keeps the font's default tracking. Large headlines usually look better tightened slightly, so a small negative value is the deliberate choice.
- Why not D: A positive `px` value loosens spacing and does not scale with the font. Use `em` for letter-spacing so it stays proportional when the font-size changes.

## Remember this

- Use the UNITLESS form for `line-height` (`1.5`, not `1.5em` or `150%`). It is inherited as a multiplier so spacing stays proportional at every font-size.
- `rem` for `font-size` is predictable because it never compounds. `em` and `%` are relative to the parent and compound when nested.
- The `font` shorthand resets every omitted sub-property to its initial value. Always include `line-height` after the slash or write the sub-properties separately.
- `letter-spacing` tightens (negative) or loosens (positive) between characters; `word-spacing` only affects gaps between words. Both inherit.
