Line height controls the space between lines of text. It makes reading easier and the page look neat.
Line height in CSS
Start learning this pattern below
Jump into concepts and practice - no test required
line-height: normal | number | length | percentage;normal uses the browser's default spacing.
A number multiplies the font size to set line height (e.g., 1.5 means 1.5 times the font size).
line-height: normal;line-height: 1.5;
line-height: 24px;
line-height: 150%;
This example shows three paragraphs with different line heights. You can see how the space between lines changes and affects readability.
<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8" /> <meta name="viewport" content="width=device-width, initial-scale=1" /> <title>Line Height Example</title> <style> body { font-family: Arial, sans-serif; margin: 2rem; } .normal { line-height: normal; background-color: #f0f8ff; padding: 1rem; margin-bottom: 1rem; } .one-point-five { line-height: 1.5; background-color: #e6ffe6; padding: 1rem; margin-bottom: 1rem; } .fixed { line-height: 2rem; background-color: #fff0f5; padding: 1rem; } </style> </head> <body> <section> <h1>Line Height Examples</h1> <article class="normal"> <p>This paragraph uses <strong>normal</strong> line height. The space between lines is the browser default.</p> </article> <article class="one-point-five"> <p>This paragraph uses a line height of <strong>1.5</strong>. The lines have more space, making it easier to read.</p> </article> <article class="fixed"> <p>This paragraph uses a fixed line height of <strong>2rem</strong>. The space between lines is exactly 2 rem units.</p> </article> </section> </body> </html>
Using a number (like 1.5) is recommended because it scales with font size and keeps spacing consistent.
Fixed lengths (like 24px or 2rem) can cause text to look cramped or too spaced if font size changes.
Good line height improves reading comfort, especially on long paragraphs.
Line height controls vertical space between lines of text.
Use numbers like 1.5 for flexible, readable spacing.
Adjust line height to improve text clarity and page design.
Practice
line-height control in a webpage?Solution
Step 1: Understand the property purpose
Theline-heightproperty sets the amount of vertical space between lines of text in a block.Step 2: Compare options to definition
Only The vertical space between lines of text correctly describes vertical spacing between lines, others describe unrelated text styles.Final Answer:
The vertical space between lines of text -> Option AQuick Check:
Line height = vertical spacing [OK]
- Confusing line height with font size
- Thinking it controls text color
- Mixing it up with letter spacing
Solution
Step 1: Recall CSS property syntax
CSS properties use hyphenated names and colon to assign values, ending with semicolon.Step 2: Check each option
line-height: 1.5; uses correct CSS syntax:line-height: 1.5;. Options B and C use incorrect assignment or units, D uses camelCase which is invalid in CSS.Final Answer:
line-height: 1.5; -> Option BQuick Check:
CSS property syntax = property: value; [OK]
- Using equals sign instead of colon
- Adding units like px to unitless line height
- Using camelCase instead of hyphen
p { font-size: 16px; line-height: 2; }What is the computed line height in pixels for the paragraph text?
Solution
Step 1: Understand line-height as a multiplier
When line-height is a number (like 2), it multiplies the font size to get the line height in pixels.Step 2: Calculate line height
Font size is 16px, line-height is 2, so 16px x 2 = 32px.Final Answer:
32px -> Option CQuick Check:
Line height = font size x number [OK]
- Confusing line-height number as pixels directly
- Using line-height value as font size
- Ignoring multiplication and picking wrong units
p { line-height: 20; }What is the error?
Solution
Step 1: Check line-height value type
The value 20 without units is treated as a multiplier, but 20 is unusually large and likely intended as pixels.Step 2: Identify missing units
To specify exact pixel spacing, units like 'px' are required:line-height: 20px;. Without units, 20 means 20 times font size, which is huge and may cause unexpected layout.Final Answer:
Missing units like 'px' for line-height value -> Option AQuick Check:
Units needed for absolute line height values [OK]
- Using large numbers without units expecting pixels
- Thinking line-height can't be set on paragraphs
- Misspelling property name
Solution
Step 1: Understand responsive units
Usingremunits for font size scales text with root font size, good for responsiveness.Step 2: Use unitless line-height for flexibility
Settingline-height: 1.5;as a number scales line height relative to font size, adapting well on different devices.Step 3: Compare options
p { font-size: 1.2rem; line-height: 1.5; } uses rem for font size and unitless line-height, making it flexible. Options B and C fix line height in pixels, less flexible. p { font-size: 16px; line-height: 1.5rem; } mixes units incorrectly.Final Answer:
p { font-size: 1.2rem; line-height: 1.5; } -> Option DQuick Check:
Unitless line-height + rem font size = responsive text [OK]
- Using fixed pixel line height with scalable font size
- Mixing units in line-height property
- Not using unitless line-height for flexible spacing
