Line Height
Table of Contents + β
In the last lesson you learned about Font Weight. That controlled how thick or thin your letters look. Now letβs look at the space between the lines of your text. This is called line height.
π What is Line Height?
When you write a paragraph with many lines, each line sits above the next one. The gap from one line to the next is the line height. Line height is the full height of each line of text. It includes the words plus the little bit of space above and below them.
Think of a school notebook. The ruled lines on the page are not stuck together. There is a fixed gap between each line. So your handwriting has room to breathe. Line height is that same gap, but for text on a web page.
So line height is not about the letters themselves. It is about how far apart the lines sit from each other.
π€ Why Do We Need It?
Here is the real problem. By default, text lines can sit very close together. When the lines are too tight, your eyes get tired. You finish one line, jump to the next, and lose your place. Reading becomes hard work.
Good line height fixes this. Here is what it gives you:
- More space between lines. So each line is easy to follow.
- Text that feels calm and clean, not crammed.
- Easier reading for long paragraphs, like a blog post or a news article.
Big sites like Medium and the Netflix help pages use generous line height. Generous just means roomy, with plenty of space. That is one reason their text feels nice to read.
π§© The Syntax
The property is called line-height. You give it a value, and that value decides the gap.
Here is the basic shape of it.
p { line-height: 1.5;}That 1.5 means each line takes one and a half times the font size. So if your font is 20px, each line will be 30px tall. A plain number like 1.5 is the best way to write it. We will see why soon.
You can write line height in a few ways. Here are the common ones.
/* β
Good: a plain number (no unit) */p { line-height: 1.5; }
/* OK: a fixed pixel value */p { line-height: 30px; }
/* OK: a percentage */p { line-height: 150%; }The plain number is special. A number with no unit means βthis many times the font size of the elementβ. So the gap scales with the font. If the font grows, the gap grows too. A pixel value does not do that. It stays the same no matter what.
π A Simple Example
Letβs see two paragraphs. One has tight lines. The other has comfortable lines.
First the HTML with two paragraphs.
<p class="tight">This text has very little space between its lines. Read it and notice how the lines feel close and crammed together on the page.</p>
<p class="airy">This text has more space between its lines. Read it and notice how each line is easy to follow and the paragraph feels calm.</p>Now the CSS that gives each paragraph a different line height.
.tight { line-height: 1;}
.airy { line-height: 1.8;}The first paragraph uses 1. So the lines sit right on top of each other. The second uses 1.8. So there is a clear gap between every line.
What you see
The first paragraph looks squashed. The lines almost touch, and your eyes have to work to read it. The second paragraph looks open and relaxed. There is a clear space between each line, so it is much easier to read.
The word airy here just means full of space and easy to breathe in. That is the feeling good line height gives your text.
π‘ A Real Example
Imagine you are making a blog post page. The article has long paragraphs. You want people to actually finish reading.
Here you set a comfortable line height on the article text.
.article { font-size: 18px; line-height: 1.6; color: #333;}That line-height: 1.6 gives each line enough room. The font is 18px. So each line becomes about 29px tall. The text now reads like a clean article, not a wall of words stuck together.
For body text, a value between 1.4 and 1.7 works well. Headings can use a smaller value, like 1.1 or 1.2. They are big and usually short, so they do not need as much room.
β οΈ Common Mistakes
A few things trip people up with line height. Letβs go through them.
- Setting line height too small. A value like
1or0.9makes lines touch and look cramped. Give your body text room. - Setting it too big. A value like
3spreads lines so far apart that they stop feeling like one paragraph. - Always using a fixed
pxvalue. If the font size later changes, the gap will not grow with it. The text can then look wrong.
Here is that fixed value trap shown in code.
/* β Avoid: fixed gap that ignores font size */p { line-height: 24px; }
/* β
Better: gap that scales with the font */p { line-height: 1.5; }If the font later grows to 30px, the 24px line height becomes too small and the lines start to overlap. The plain number 1.5 would just grow along with the font.
β Best Practices
Keep these simple habits in mind and your text will read well.
- Use a plain number, like
1.5, not a fixedpxvalue. It scales with the font. - For paragraphs and body text, stay around
1.4to1.7. - For large headings, use a smaller value, like
1.1or1.2. - Check your text on a phone screen too. Lines that look fine on a laptop can feel tight on a small screen.
π§© What Youβve Learned
Letβs quickly go over what we covered here.
- β Line height is the space between the lines of your text, like the gap between ruled lines in a notebook.
- β Good line height makes long text easy and calm to read.
- β
The property is
line-height, and a plain number like1.5is the best value to use. - β
A plain number scales with the font size, but a fixed
pxvalue does not. - β
Body text reads well around
1.4to1.7, and headings use a smaller value.
Check Your Knowledge
Test what you learned. Pick an answer for each question, then click Check.
- 1
What does line-height control?
Why: Line height sets the gap between each line of text, like the space between ruled lines in a notebook.
- 2
Why is a plain number like 1.5 better than a fixed value like 24px?
Why: A plain number means a multiple of the font size, so the line gap grows or shrinks as the font changes. A fixed px value stays the same.
- 3
Which line-height is a good choice for normal body text?
Why: Body text reads well between about 1.4 and 1.7. A value like 1.5 gives comfortable spacing.
- 4
What happens if you set line-height too small, like 1?
Why: A very small line height makes lines sit too close together, so the text feels squashed and is tiring to read.
π Whatβs Next?
Now that your lines have good spacing, letβs learn how to position your text on the left, the right, or in the center of the page.