Pebellslearn by building
0%
RoadmapsMatrixCoursesSandboxSign in
Fonts and Text Styling  ›  Capstone Project

Line Height and Text Spacing

Line Height 15 minA unitless line-height is inherited as a factor that scales with each element's font size, while letter-spacing, word-spacing and text-transform fine-tune how a line reads.

Line Height and Text Spacing

The café's menu uses a beautiful font at the right size, yet descriptions still feel cramped and hard to read. The usual culprit is not the font at all. It is the space between the lines and between the letters.

The rule

Give lines room with a unitless line-height; nudge letters in em.

line-height sets the height of each line of text. Long reading text is comfortable at about 1.4 to 1.6 times the font size; big headings look better tighter, around 1.1 to 1.25.

Use a unitless number, and the reason is inheritance:

  • line-height: 1.5 passes the factor down. Each element multiplies it by its own font size.
  • line-height: 1.5em or 24px is converted to a length once, on the element where you set it, and that fixed length is what children inherit.
body {
  font-size: 1rem;
  line-height: 1.5;   /* every element gets 1.5 × its own size */
}
h1 {
  font-size: 2.5rem;
  line-height: 1.15;
}

The spacing properties fine-tune the gaps inside a line:

  • letter-spacing adds space between characters. Small caps and all-caps labels read better with a little extra, such as 0.05em. Using em means the gap scales with the text.
  • word-spacing adds space between words. Rarely needed, but handy for spaced-out labels.
  • text-transform changes the displayed case, such as uppercase, without changing the text in the HTML.
.site-nav a {
  text-transform: uppercase;
  letter-spacing: 0.08em;
}

The HTML still says "Menu" and "Visit"; only the display shows "MENU" and "VISIT", so the words stay easy to edit and translate.

The shortcut

For line height, multiply on the element that shows the text, then check what was inherited: a factor or a fixed length.

Why does the big heading overlap itself?Step 1 of 4
  1. The rules

    body { font-size: 16px; line-height: 1.5em; } and h1 { font-size: 40px; }.

Drills

Answer fast — trust the rule.

quick drill

body has line-height: 1.5. An h1 inside it has font-size: 32px and no line-height rule. What is the h1's line height?

quick drill

body has font-size: 16px; line-height: 1.5em;. What line height does a 32px h1 inside it get?

quick drill

Which line height suits long paragraphs of body text?

quick drill

The nav shows "MENU" because of text-transform: uppercase. What does the HTML contain?

quick drill

Why write letter-spacing: 0.05em instead of 1px?

Remember

  • Reading text: line-height around 1.5, written without a unit.
  • A unitless factor is inherited as a factor; em or px is inherited as a fixed length.
  • letter-spacing in em scales with the text; text-transform changes display, not content.

Practice — level up

0/1 solved

Write your answer, then compare it with a rubric and a model answer.

ExplainStyle the menu text

Write the CSS that sets comfortable body text for the café page and uppercase, slightly spaced nav links. Explain why you chose a unitless line height and an em letter spacing.