Line Height
The line-height property sets the height of each line of text, and so also the spacing between the lines. Longer text is easier to read when the lines aren't too close together.
The best way to write it is a number without a unit. It means a multiple of the element's font size:
p {
font-size: 20px;
line-height: 1.5;
}Here each line is 1.5 × 20 = 30 pixels high. The space the letters don't need is split evenly above and below the text, so the text sits in the middle of its line.
By default, browsers use line-height: normal, which is about 1.2, depending on the font. For paragraphs, values between 1.4 and 1.8 are easier to read. Compare line-height: 1 and line-height: 1.8:
The domestic cat sleeps for 12 to 16 hours a day. It is most active in the evening and early in the morning, when it likes to hunt and play.
The domestic cat sleeps for 12 to 16 hours a day. It is most active in the evening and early in the morning, when it likes to hunt and play.
We could also write line-height: 30px, but a number without a unit is better, because it grows with the font size. If we later changed the font size to 30 pixels, the line height would become 45 pixels, while 30px would stay 30 pixels and the lines would be cramped.
Instructions
- 1
Create a rule for paragraphs (
p) that setsline-heightto1.6.